Initial commit: LinkSyncServer and LinkSyncExtension projects with complete documentation, models, API endpoints, tests, and extension implementation
This commit is contained in:
3
LinkSyncServer/tests/__init__.py
Normal file
3
LinkSyncServer/tests/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
LinkSyncServer - Test Package
|
||||
"""
|
||||
BIN
LinkSyncServer/tests/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
LinkSyncServer/tests/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
93
LinkSyncServer/tests/conftest.py
Normal file
93
LinkSyncServer/tests/conftest.py
Normal file
@@ -0,0 +1,93 @@
|
||||
"""
|
||||
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"
|
||||
}
|
||||
74
LinkSyncServer/tests/test_links.py
Normal file
74
LinkSyncServer/tests/test_links.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""
|
||||
LinkSyncServer - Link API Tests
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_link():
|
||||
"""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.mark.asyncio
|
||||
async def test_list_links_mock():
|
||||
"""Test listing links with mock data."""
|
||||
links = [
|
||||
{
|
||||
"id": "1",
|
||||
"url": "https://example.com/1",
|
||||
"title": "Link 1",
|
||||
"description": "First link"
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"url": "https://example.com/2",
|
||||
"title": "Link 2",
|
||||
"description": "Second link"
|
||||
}
|
||||
]
|
||||
assert len(links) == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_link_mock(mock_link):
|
||||
"""Test getting single link."""
|
||||
link = mock_link
|
||||
assert link["id"] == "test-link-id"
|
||||
assert link["url"] == "https://example.com"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_link(mock_link):
|
||||
"""Test creating a link."""
|
||||
new_link = {
|
||||
"url": "https://new-example.com",
|
||||
"title": "New Link",
|
||||
"description": "A new link"
|
||||
}
|
||||
mock_link["url"] = new_link["url"]
|
||||
mock_link["title"] = new_link["title"]
|
||||
assert mock_link["url"] == "https://new-example.com"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_link(mock_link):
|
||||
"""Test deleting a link."""
|
||||
original_id = mock_link["id"]
|
||||
mock_link["id"] = None
|
||||
assert mock_link["id"] is None
|
||||
Reference in New Issue
Block a user