Files
py-wikijs/examples/quick_test.py
Claude 54de1ea8e1 docs: Add installation guide and quick test script
Added comprehensive documentation to help users install and test
py-wikijs in their projects before public release.

Changes:
- INSTALLATION_GUIDE.md: Complete guide for all installation methods
  * GitHub installation (recommended for now)
  * requirements.txt integration
  * pyproject.toml integration
  * Local development setup
  * Usage examples and troubleshooting

- examples/quick_test.py: Verification script
  * Tests package import
  * Tests Wiki.js connectivity (optional)
  * Validates feature availability
  * Provides clear diagnostic output

This prepares the package for testing in external projects before
making the repository public.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-25 19:29:57 +00:00

152 lines
4.2 KiB
Python
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Quick test script to verify py-wikijs installation and connectivity.
This script helps you verify that py-wikijs is installed correctly and can
connect to your Wiki.js instance.
Usage:
python quick_test.py
Or set environment variables:
export WIKIJS_URL="https://your-wiki.example.com"
export WIKIJS_API_KEY="your-api-key-here"
python quick_test.py
"""
import os
import sys
from typing import Optional
def test_import() -> bool:
"""Test that py-wikijs can be imported."""
print("=" * 60)
print("TEST 1: Package Import")
print("=" * 60)
try:
from wikijs import WikiJSClient, __version__
print(f"✅ Successfully imported py-wikijs v{__version__}")
return True
except ImportError as e:
print(f"❌ Failed to import py-wikijs: {e}")
print("\nInstall with: pip install git+https://github.com/l3ocho/py-wikijs.git@v0.1.0")
return False
def test_connectivity(url: Optional[str] = None, api_key: Optional[str] = None) -> bool:
"""Test connectivity to Wiki.js instance."""
print("\n" + "=" * 60)
print("TEST 2: Wiki.js Connectivity")
print("=" * 60)
# Get credentials
url = url or os.getenv("WIKIJS_URL")
api_key = api_key or os.getenv("WIKIJS_API_KEY")
if not url or not api_key:
print("⚠️ Skipping connectivity test - credentials not provided")
print("\nTo test connectivity, set environment variables:")
print(" export WIKIJS_URL='https://your-wiki.example.com'")
print(" export WIKIJS_API_KEY='your-api-key-here'")
return False
try:
from wikijs import WikiJSClient
print(f"🔗 Connecting to: {url}")
client = WikiJSClient(url=url, auth=api_key)
# Try to list pages
pages = client.pages.list()
print(f"✅ Successfully connected to Wiki.js")
print(f"✅ Found {len(pages)} page(s)")
# Show first page if available
if pages:
first_page = pages[0]
print(f"\nFirst page:")
print(f" - ID: {first_page.id}")
print(f" - Title: {first_page.title}")
print(f" - Path: {first_page.path}")
return True
except Exception as e:
print(f"❌ Failed to connect: {e}")
print("\nPlease verify:")
print(" 1. Wiki.js URL is correct and accessible")
print(" 2. API key is valid and has necessary permissions")
print(" 3. Wiki.js version is 2.2 or higher (not 3.x)")
return False
def test_features() -> bool:
"""Test that key features are available."""
print("\n" + "=" * 60)
print("TEST 3: Feature Availability")
print("=" * 60)
try:
from wikijs import (
APIKeyAuth,
AuthenticationError,
JWTAuth,
Page,
PageCreate,
WikiJSClient,
)
print("✅ Core client: WikiJSClient")
print("✅ Authentication: APIKeyAuth, JWTAuth")
print("✅ Models: Page, PageCreate")
print("✅ Exceptions: AuthenticationError")
print("✅ All core features available")
return True
except ImportError as e:
print(f"❌ Missing features: {e}")
return False
def main() -> int:
"""Run all tests."""
print("\n🧪 py-wikijs Installation & Connectivity Test")
print("=" * 60)
results = []
# Test 1: Import
results.append(test_import())
# Test 2: Connectivity (optional)
results.append(test_connectivity())
# Test 3: Features
results.append(test_features())
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
passed = sum(results)
total = len(results)
print(f"Tests passed: {passed}/{total}")
if all(results):
print("\n🎉 All tests passed! py-wikijs is ready to use.")
return 0
elif results[0] and results[2]: # Import and features work
print("\n✅ Installation verified!")
print(" Set WIKIJS_URL and WIKIJS_API_KEY to test connectivity")
return 0
else:
print("\n❌ Some tests failed. Please check the errors above.")
return 1
if __name__ == "__main__":
sys.exit(main())