Files
myworkspace/LinkSyncServer/tests/test_links.py
DavidSaylor 09d30427f4 Complete LinkSyncServer and LinkSyncExtension implementation
LinkSyncServer:
- Fix app.py imports, add CORS middleware, lifespan events
- Create api/routes.py router aggregator
- Create config/settings.py for centralized configuration
- Rewrite models/base.py with proper relationships and serialization
- Rewrite all API endpoints with real DB integration (auth, links, collections, sync, queries, tags)
- Add admin endpoints (user management, stats, audit log)
- Complete query parser with recursive descent and proper precedence
- Complete query executor with set operations and field filters
- Set up Alembic migrations with initial schema
- Create web interface (templates, CSS, JS)
- Add 42 passing tests (auth, links, collections, queries)
- Add deploy.ps1 and deploy.sh scripts
- Update README with deployment workflow

LinkSyncExtension:
- Create utils/api.js (REST client with retries, auth, error handling)
- Create utils/sync.js (3 sync modes + conflict detection)
- Create utils/collection.js (collection management)
- Create utils/query-engine.js (client-side query parser)
- Rewrite background.js (sync loop, bookmark events, message routing)
- Rewrite popup.js (tabs, settings modal, notifications, CRUD)
- Update popup.html (tabbed interface, query builder, modal)
- Update popup.css (full redesign)
- Create content/content.js (page metadata extraction)
- Create options.html/js (dedicated settings page)
- Generate icons (48x48, 96x96)
- Update manifest.json (host permissions, content scripts, options)
- Create AGENTS.md
2026-05-19 13:21:26 -05:00

91 lines
4.3 KiB
Python

"""
LinkSyncServer - Link API Tests
"""
import pytest
from fastapi.testclient import TestClient
class TestLinks:
def test_create_bookmark(self, client: TestClient, auth_headers: dict, sample_bookmark_data: dict):
response = client.post("/api/links/", json=sample_bookmark_data, headers=auth_headers)
assert response.status_code == 201
data = response.json()
assert data["url"] == sample_bookmark_data["url"]
assert data["title"] == sample_bookmark_data["title"]
assert data["tags"] == sample_bookmark_data["tags"]
def test_list_bookmarks(self, client: TestClient, auth_headers: dict, sample_bookmark_data: dict):
client.post("/api/links/", json=sample_bookmark_data, headers=auth_headers)
response = client.get("/api/links/", headers=auth_headers)
assert response.status_code == 200
assert isinstance(response.json(), list)
def test_get_bookmark(self, client: TestClient, auth_headers: dict, sample_bookmark_data: dict):
create_resp = client.post("/api/links/", json=sample_bookmark_data, headers=auth_headers)
bookmark_id = create_resp.json()["id"]
response = client.get(f"/api/links/{bookmark_id}", headers=auth_headers)
assert response.status_code == 200
assert response.json()["id"] == bookmark_id
def test_get_bookmark_not_found(self, client: TestClient, auth_headers: dict):
response = client.get("/api/links/nonexistent-id", headers=auth_headers)
assert response.status_code == 404
def test_update_bookmark(self, client: TestClient, auth_headers: dict, sample_bookmark_data: dict):
create_resp = client.post("/api/links/", json=sample_bookmark_data, headers=auth_headers)
bookmark_id = create_resp.json()["id"]
response = client.put(
f"/api/links/{bookmark_id}",
json={"title": "Updated Title"},
headers=auth_headers,
)
assert response.status_code == 200
assert response.json()["title"] == "Updated Title"
def test_delete_bookmark(self, client: TestClient, auth_headers: dict, sample_bookmark_data: dict):
create_resp = client.post("/api/links/", json=sample_bookmark_data, headers=auth_headers)
bookmark_id = create_resp.json()["id"]
response = client.delete(f"/api/links/{bookmark_id}", headers=auth_headers)
assert response.status_code == 200
assert response.json()["deleted_id"] == bookmark_id
def test_add_tags(self, client: TestClient, auth_headers: dict, sample_bookmark_data: dict):
create_resp = client.post("/api/links/", json=sample_bookmark_data, headers=auth_headers)
bookmark_id = create_resp.json()["id"]
response = client.post(
f"/api/links/{bookmark_id}/tags",
json={"tags": ["new-tag", "another-tag"]},
headers=auth_headers,
)
assert response.status_code == 200
tags = response.json()["tags"]
assert "new-tag" in tags or "another-tag" in tags
def test_remove_tags(self, client: TestClient, auth_headers: dict, sample_bookmark_data: dict):
create_resp = client.post("/api/links/", json=sample_bookmark_data, headers=auth_headers)
bookmark_id = create_resp.json()["id"]
response = client.request(
"DELETE",
f"/api/links/{bookmark_id}/tags",
json={"tags": ["test"]},
headers=auth_headers,
)
assert response.status_code in (200, 422)
def test_search_bookmarks(self, client: TestClient, auth_headers: dict, sample_bookmark_data: dict):
client.post("/api/links/", json=sample_bookmark_data, headers=auth_headers)
response = client.get("/api/links/", params={"search": "example"}, headers=auth_headers)
assert response.status_code == 200
assert len(response.json()) >= 1
def test_pagination(self, client: TestClient, auth_headers: dict, sample_bookmark_data: dict):
for i in range(5):
data = sample_bookmark_data.copy()
data["url"] = f"https://example{i}.com"
data["title"] = f"Example {i}"
client.post("/api/links/", json=data, headers=auth_headers)
response = client.get("/api/links/", params={"limit": 2, "offset": 0}, headers=auth_headers)
assert response.status_code == 200
assert len(response.json()) <= 2