93 lines
2.5 KiB
Python
93 lines
2.5 KiB
Python
"""
|
|
LinkSyncServer - Test Configuration
|
|
"""
|
|
|
|
import pytest
|
|
from sqlalchemy import create_engine
|
|
|
|
# Mock models for testing without full database
|
|
mock_db = {
|
|
"users": [
|
|
{"id": "test-user-id", "username": "testuser", "email": "test@example.com", "role": "admin"}
|
|
],
|
|
"links": [],
|
|
"collections": [
|
|
{"id": "mock-id", "name": "Test Collection", "query_type": "dynamic"}
|
|
]
|
|
}
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
def test_data():
|
|
"""Get mock test data."""
|
|
return mock_db
|
|
|
|
|
|
@pytest.fixture
|
|
def auth_headers():
|
|
"""Get auth headers for API calls."""
|
|
return {'Authorization': 'Token test_api_key'}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_client(test_data):
|
|
"""Create mock client for API testing."""
|
|
class MockClient:
|
|
def __init__(self, data):
|
|
self.data = data
|
|
|
|
def get(self, endpoint, headers=None):
|
|
# Mock GET requests
|
|
return self._make_request(endpoint, headers)
|
|
|
|
def post(self, endpoint, data=None, headers=None):
|
|
# Mock POST requests
|
|
return self._make_request(endpoint, headers)
|
|
|
|
def delete(self, endpoint, headers=None):
|
|
# Mock DELETE requests
|
|
return self._make_request(endpoint, headers)
|
|
|
|
def _make_request(self, endpoint, headers):
|
|
# Return mock response
|
|
return type('Response', (), {
|
|
'status_code': 200,
|
|
'json': lambda: self.data.get(endpoint.replace('/', ''), {})
|
|
})()
|
|
|
|
return MockClient(test_data)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_link(test_data):
|
|
"""Get mock bookmark data."""
|
|
return {
|
|
"id": "test-link-id",
|
|
"url": "https://example.com",
|
|
"title": "Test Link",
|
|
"description": "A test link",
|
|
"notes": "",
|
|
"tags": ["test", "demo"],
|
|
"favicon_url": None,
|
|
"path": "/Test",
|
|
"created_at": "2026-05-11T00:00:00Z",
|
|
"updated_at": "2026-05-11T00:00:00Z",
|
|
"visit_count": 0,
|
|
"is_bookmarked": False,
|
|
"source_set_id": None
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_collection(test_data):
|
|
"""Get mock collection data."""
|
|
return {
|
|
"id": "test-collection-id",
|
|
"name": "Test Collection",
|
|
"description": "A test collection",
|
|
"query_type": "dynamic",
|
|
"query_expression": {"operation": "OR", "operands": []},
|
|
"is_public": False,
|
|
"created_at": "2026-05-11T00:00:00Z",
|
|
"updated_at": "2026-05-11T00:00:00Z"
|
|
} |