7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
115 lines
4.2 KiB
Python
115 lines
4.2 KiB
Python
"""
|
|
pytest-compatible API tests for REST API endpoints.
|
|
Tests basic functionality and programmatic access integration.
|
|
"""
|
|
|
|
import json
|
|
|
|
|
|
class TestRestAPIBasic:
|
|
"""Basic tests for REST API endpoints."""
|
|
|
|
def test_health_check(self, authenticated_client):
|
|
"""Test the health check endpoint returns OK status."""
|
|
response = authenticated_client.get("/api/v1/health")
|
|
assert response.status_code == 200
|
|
|
|
data = json.loads(response.data)
|
|
assert data["status"] == "ok"
|
|
assert "timestamp" in data
|
|
assert isinstance(data["timestamp"], (int, float))
|
|
|
|
def test_api_documentation(self, authenticated_client):
|
|
"""Test the API documentation endpoint returns proper structure."""
|
|
response = authenticated_client.get("/api/v1/")
|
|
assert response.status_code == 200
|
|
|
|
data = json.loads(response.data)
|
|
assert data["api_version"] == "v1"
|
|
assert "description" in data
|
|
assert "endpoints" in data
|
|
assert len(data["endpoints"]) >= 3
|
|
|
|
# Verify endpoint structure
|
|
endpoints = data["endpoints"]
|
|
if isinstance(endpoints, list):
|
|
# For list format, just check basic fields
|
|
for endpoint in endpoints:
|
|
assert "path" in endpoint or "endpoint" in endpoint
|
|
assert "method" in endpoint or "methods" in endpoint
|
|
assert "description" in endpoint
|
|
# auth_required field is optional in API v1
|
|
else:
|
|
# For dict format
|
|
for endpoint in endpoints.values():
|
|
assert "path" in endpoint
|
|
assert "methods" in endpoint
|
|
assert "description" in endpoint
|
|
assert "requires_auth" in endpoint
|
|
|
|
def test_quick_summary_validation(self, authenticated_client):
|
|
"""Test quick_summary endpoint validates required fields."""
|
|
# Test missing query
|
|
response = authenticated_client.post(
|
|
"/api/v1/quick_summary",
|
|
json={},
|
|
content_type="application/json",
|
|
)
|
|
assert response.status_code == 400
|
|
data = json.loads(response.data)
|
|
assert "error" in data
|
|
assert "query" in data["error"].lower()
|
|
|
|
def test_analyze_documents_validation(self, authenticated_client):
|
|
"""Test analyze_documents endpoint validates required fields."""
|
|
# Test missing collection_name
|
|
response = authenticated_client.post(
|
|
"/api/v1/analyze_documents",
|
|
json={"query": "test query"},
|
|
content_type="application/json",
|
|
)
|
|
assert response.status_code == 400
|
|
data = json.loads(response.data)
|
|
assert "error" in data
|
|
assert "collection_name" in data["error"].lower()
|
|
|
|
# Test missing query
|
|
response = authenticated_client.post(
|
|
"/api/v1/analyze_documents",
|
|
json={"collection_name": "test_collection"},
|
|
content_type="application/json",
|
|
)
|
|
assert response.status_code == 400
|
|
data = json.loads(response.data)
|
|
assert "error" in data
|
|
assert "query" in data["error"].lower()
|
|
|
|
def test_generate_report_validation(self, authenticated_client):
|
|
"""Test generate_report endpoint validates required fields."""
|
|
# Test missing research_id or query
|
|
response = authenticated_client.post(
|
|
"/api/v1/generate_report",
|
|
json={},
|
|
content_type="application/json",
|
|
)
|
|
assert response.status_code == 400
|
|
data = json.loads(response.data)
|
|
assert "error" in data
|
|
# Check for either research_id or query in error message
|
|
error_msg = data["error"].lower()
|
|
assert (
|
|
"research_id" in error_msg
|
|
or "query" in error_msg
|
|
or "required" in error_msg
|
|
)
|
|
|
|
def test_error_response_format(self, authenticated_client):
|
|
"""Test that error responses follow consistent format."""
|
|
# Trigger a 404 error
|
|
response = authenticated_client.get("/api/v1/nonexistent_endpoint")
|
|
assert response.status_code == 404
|
|
|
|
if response.content_type == "application/json":
|
|
data = json.loads(response.data)
|
|
assert "error" in data or "message" in data
|