Fix 3 critical issues identified in repository review

**Critical Fixes:**

1. **Fixed Error Hierarchy** (wikijs/exceptions.py)
   - ConnectionError and TimeoutError now properly inherit from APIError
   - Ensures consistent exception handling across the SDK
   - Added proper __init__ methods with status_code=None

2. **Fixed test_connection Method** (wikijs/client.py)
   - Changed from basic HTTP GET to proper GraphQL query validation
   - Now uses query { site { title } } to validate API connectivity
   - Provides better error messages for authentication failures
   - Validates both connectivity AND API access

3. **Implemented JWT Token Refresh** (wikijs/auth/jwt.py)
   - Added base_url parameter to JWTAuth class
   - Implemented complete refresh() method with HTTP request to /api/auth/refresh
   - Handles token, refresh token, and expiration updates
   - Proper error handling for network failures and auth errors

**Bonus Fixes:**
- Dynamic user agent version (uses __version__ from version.py instead of hardcoded)
- Updated all JWT tests to include required base_url parameter
- Updated test mocks to match new GraphQL-based test_connection

**Test Results:**
- All 231 tests passing 
- Test coverage: 91.64% (target: 85%) 
- No test failures or errors

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2025-10-22 17:44:44 +00:00
parent 3e2430fbe0
commit 66f4471e53
6 changed files with 197 additions and 94 deletions

View File

@@ -25,9 +25,9 @@ def api_key_auth(mock_api_key):
@pytest.fixture
def jwt_auth(mock_jwt_token):
def jwt_auth(mock_jwt_token, mock_wiki_base_url):
"""Fixture providing JWTAuth instance."""
return JWTAuth(mock_jwt_token)
return JWTAuth(mock_jwt_token, mock_wiki_base_url)
@pytest.fixture