Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(tests): narrow broad status-code tautologies in test_library_routes.py (#4135)

LearningCircuitd4159916b928
diff --git a/tests/research_library/routes/test_library_routes.py b/tests/research_library/routes/test_library_routes.py
index 51f88ccac6..996ebbaa86 100644
--- a/tests/research_library/routes/test_library_routes.py
+++ b/tests/research_library/routes/test_library_routes.py
@@ -653,7 +653,7 @@ class TestLibraryApiRoutes:
with _authenticated_client(app) as client:
response = client.get("/library/api/stats")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_get_collections_list_route(self):
"""Test /api/collections/list endpoint exists."""
@@ -661,7 +661,7 @@ class TestLibraryApiRoutes:
with _authenticated_client(app) as client:
response = client.get("/library/api/collections/list")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_get_documents_route(self):
"""Test /api/documents endpoint exists."""
@@ -669,7 +669,7 @@ class TestLibraryApiRoutes:
with _authenticated_client(app) as client:
response = client.get("/library/api/documents")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_toggle_favorite_route(self):
"""Test toggle favorite endpoint exists."""
@@ -679,7 +679,7 @@ class TestLibraryApiRoutes:
response = client.post(
"/library/api/document/test-doc/toggle-favorite"
)
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 404, response.status_code
def test_delete_document_route(self):
"""Test delete document endpoint exists."""
@@ -687,7 +687,7 @@ class TestLibraryApiRoutes:
with _authenticated_client(app) as client:
response = client.delete("/library/api/document/test-doc")
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 200, response.status_code
class TestLibraryPageRoutes:
@@ -699,7 +699,7 @@ class TestLibraryPageRoutes:
with _authenticated_client(app) as client:
response = client.get("/library/")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 500, response.status_code
def test_document_details_page_route_exists(self):
"""Test /document/<id> page route exists."""
@@ -707,7 +707,7 @@ class TestLibraryPageRoutes:
with _authenticated_client(app) as client:
response = client.get("/library/document/test-doc-id")
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 200, response.status_code
def test_download_manager_page_route_exists(self):
"""Test /download-manager page route exists."""
@@ -715,7 +715,7 @@ class TestLibraryPageRoutes:
with _authenticated_client(app) as client:
response = client.get("/library/download-manager")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 500, response.status_code
class TestDownloadApiRoutes:
@@ -727,7 +727,7 @@ class TestDownloadApiRoutes:
with _authenticated_client(app) as client:
response = client.post("/library/api/download/123")
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 500, response.status_code
def test_download_research_pdfs_route(self):
"""Test /api/download-research/<id> endpoint exists."""
@@ -737,7 +737,7 @@ class TestDownloadApiRoutes:
response = client.post(
"/library/api/download-research/research-123"
)
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 500, response.status_code
def test_download_bulk_route(self):
"""Test /api/download-bulk endpoint exists."""
@@ -749,7 +749,7 @@ class TestDownloadApiRoutes:
json={"research_ids": []},
content_type="application/json",
)
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
def test_sync_library_route(self):
"""Test /api/sync-library endpoint exists."""
@@ -757,7 +757,7 @@ class TestDownloadApiRoutes:
with _authenticated_client(app) as client:
response = client.post("/library/api/sync-library")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_mark_for_redownload_route(self):
"""Test /api/mark-redownload endpoint exists."""
@@ -769,7 +769,7 @@ class TestDownloadApiRoutes:
json={"document_ids": []},
content_type="application/json",
)
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
class TestResearchSourcesRoute:
@@ -783,7 +783,7 @@ class TestResearchSourcesRoute:
response = client.get(
"/library/api/get-research-sources/research-123"
)
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 200, response.status_code
class TestCheckDownloadsRoute:
@@ -799,7 +799,7 @@ class TestCheckDownloadsRoute:
json={"urls": ["https://arxiv.org/abs/2301.00001"]},
content_type="application/json",
)
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
class TestDownloadSourceRoute:
@@ -815,7 +815,7 @@ class TestDownloadSourceRoute:
json={"url": "https://arxiv.org/abs/2301.00001"},
content_type="application/json",
)
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
# ============= Extended Tests for Phase 3.3 Coverage =============
@@ -830,7 +830,7 @@ class TestServePdfApi:
with _authenticated_client(app) as client:
response = client.get("/library/api/pdf/doc123")
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 404, response.status_code
def test_serve_pdf_api_nonexistent_doc(self):
"""Test serving PDF for nonexistent document."""
@@ -838,7 +838,7 @@ class TestServePdfApi:
with _authenticated_client(app) as client:
response = client.get("/library/api/pdf/nonexistent-doc-id-12345")
- assert response.status_code in [302, 401, 403, 404, 500]
+ assert response.status_code == 404, response.status_code
class TestGetPdfUrl:
@@ -850,7 +850,7 @@ class TestGetPdfUrl:
with _authenticated_client(app) as client:
response = client.get("/library/api/document/doc123/pdf-url")
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 200, response.status_code
class TestDownloadSingleResource:
@@ -862,7 +862,7 @@ class TestDownloadSingleResource:
with _authenticated_client(app) as client:
response = client.post("/library/api/download/nonexistent-doc-999")
- assert response.status_code in [302, 401, 403, 404, 500]
+ assert response.status_code == 404, response.status_code
def test_download_single_resource_with_options(self):
"""Test download with options in request body."""
@@ -874,7 +874,7 @@ class TestDownloadSingleResource:
json={"force_download": True, "storage_type": "database"},
content_type="application/json",
)
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 404, response.status_code
class TestDownloadBulk:
@@ -890,7 +890,7 @@ class TestDownloadBulk:
json={"research_ids": []},
content_type="application/json",
)
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
def test_download_bulk_with_ids(self):
"""Test bulk download with research IDs."""
@@ -902,7 +902,7 @@ class TestDownloadBulk:
json={"research_ids": ["research1", "research2"]},
content_type="application/json",
)
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_download_bulk_missing_research_ids(self):
"""Test bulk download without research_ids field."""
@@ -914,7 +914,7 @@ class TestDownloadBulk:
json={},
content_type="application/json",
)
- assert response.status_code in [302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
class TestCheckDownloads:
@@ -930,7 +930,7 @@ class TestCheckDownloads:
json={"urls": []},
content_type="application/json",
)
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
def test_check_downloads_multiple_urls(self):
"""Test check downloads with multiple URLs."""
@@ -949,7 +949,7 @@ class TestCheckDownloads:
content_type="application/json",
)
# 400 is expected when research_id is missing from the request
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
class TestMarkForRedownload:
@@ -965,7 +965,7 @@ class TestMarkForRedownload:
json={"document_ids": []},
content_type="application/json",
)
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
def test_mark_redownload_with_ids(self):
"""Test mark redownload with document IDs."""
@@ -977,7 +977,7 @@ class TestMarkForRedownload:
json={"document_ids": ["doc1", "doc2", "doc3"]},
content_type="application/json",
)
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 500, response.status_code
class TestGetDocuments:
@@ -989,7 +989,7 @@ class TestGetDocuments:
with _authenticated_client(app) as client:
response = client.get("/library/api/documents?page=2&per_page=20")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_get_documents_with_search(self):
"""Test get documents with search query."""
@@ -999,7 +999,7 @@ class TestGetDocuments:
response = client.get(
"/library/api/documents?search=machine+learning"
)
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_get_documents_with_filters(self):
"""Test get documents with filters."""
@@ -1009,7 +1009,7 @@ class TestGetDocuments:
response = client.get(
"/library/api/documents?collection_id=coll123&favorite=true"
)
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
class TestGetSingleDocument:
@@ -1022,15 +1022,7 @@ class TestGetSingleDocument:
with _authenticated_client(app) as client:
response = client.get("/library/api/document/doc123")
# 405 is expected because /api/document/<id> only supports DELETE
- assert response.status_code in [
- 200,
- 302,
- 401,
- 403,
- 404,
- 405,
- 500,
- ]
+ assert response.status_code == 405, response.status_code
class TestUpdateDocument:
@@ -1046,16 +1038,7 @@ class TestUpdateDocument:
json={"title": "Updated Title"},
content_type="application/json",
)
- assert response.status_code in [
- 200,
- 302,
- 400,
- 401,
- 403,
- 404,
- 405,
- 500,
- ]
+ assert response.status_code == 405, response.status_code
class TestDeleteDocument:
@@ -1069,7 +1052,7 @@ class TestDeleteDocument:
response = client.delete(
"/library/api/document/nonexistent-doc-999"
)
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 200, response.status_code
class TestToggleFavorite:
@@ -1083,7 +1066,7 @@ class TestToggleFavorite:
response = client.post(
"/library/api/document/nonexistent-doc-999/toggle-favorite"
)
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 404, response.status_code
class TestLibraryEdgeCases:
@@ -1098,16 +1081,7 @@ class TestLibraryEdgeCases:
"/library/api/document/'; DROP TABLE documents; --"
)
# 405 is expected because /api/document/<id> only supports DELETE
- assert response.status_code in [
- 200,
- 302,
- 400,
- 401,
- 403,
- 404,
- 405,
- 500,
- ]
+ assert response.status_code == 405, response.status_code
def test_path_traversal_in_pdf_endpoint(self):
"""Test path traversal attempt in PDF endpoint."""
@@ -1115,7 +1089,7 @@ class TestLibraryEdgeCases:
with _authenticated_client(app) as client:
response = client.get("/library/api/pdf/../../etc/passwd")
- assert response.status_code in [302, 400, 401, 403, 404, 500]
+ assert response.status_code == 404, response.status_code
def test_special_characters_in_search(self):
"""Test special characters in search query."""
@@ -1125,7 +1099,7 @@ class TestLibraryEdgeCases:
response = client.get(
"/library/api/documents?search=<script>alert('xss')</script>"
)
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_unicode_in_search(self):
"""Test unicode in search query."""
@@ -1133,7 +1107,7 @@ class TestLibraryEdgeCases:
with _authenticated_client(app) as client:
response = client.get("/library/api/documents?search=机器学习")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_negative_page_number(self):
"""Test negative page number in pagination."""
@@ -1141,7 +1115,7 @@ class TestLibraryEdgeCases:
with _authenticated_client(app) as client:
response = client.get("/library/api/documents?page=-1")
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
def test_very_large_page_number(self):
"""Test very large page number."""
@@ -1149,7 +1123,7 @@ class TestLibraryEdgeCases:
with _authenticated_client(app) as client:
response = client.get("/library/api/documents?page=999999")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
class TestAdditionalDomains:
@@ -1242,7 +1216,7 @@ class TestDownloadResearchPdfs:
response = client.post(
"/library/api/download-research/research-123"
)
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 500, response.status_code
def test_download_research_pdfs_nonexistent(self):
"""Test download research PDFs with nonexistent research ID."""
@@ -1252,7 +1226,7 @@ class TestDownloadResearchPdfs:
response = client.post(
"/library/api/download-research/nonexistent-research-999"
)
- assert response.status_code in [302, 401, 403, 404, 500]
+ assert response.status_code == 500, response.status_code
class TestGetResearchSources:
@@ -1266,7 +1240,7 @@ class TestGetResearchSources:
response = client.get(
"/library/api/get-research-sources/research-123"
)
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 200, response.status_code
def test_get_research_sources_nonexistent(self):
"""Test getting research sources with nonexistent ID."""
@@ -1277,7 +1251,7 @@ class TestGetResearchSources:
"/library/api/get-research-sources/nonexistent-research-999"
)
# 200 is returned when no resources are found (empty list)
- assert response.status_code in [200, 302, 401, 403, 404, 500]
+ assert response.status_code == 200, response.status_code
class TestSyncLibrary:
@@ -1289,7 +1263,7 @@ class TestSyncLibrary:
with _authenticated_client(app) as client:
response = client.post("/library/api/sync-library")
- assert response.status_code in [200, 302, 401, 403, 500]
+ assert response.status_code == 200, response.status_code
class TestDownloadSource:
@@ -1305,7 +1279,7 @@ class TestDownloadSource:
json={},
content_type="application/json",
)
- assert response.status_code in [302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
def test_download_source_with_options(self):
"""Test download source with options."""
@@ -1321,7 +1295,7 @@ class TestDownloadSource:
},
content_type="application/json",
)
- assert response.status_code in [200, 302, 400, 401, 403, 500]
+ assert response.status_code == 400, response.status_code
class TestResourceIdExtractionFromFilenames: