-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_app.py
More file actions
81 lines (71 loc) · 2.91 KB
/
test_app.py
File metadata and controls
81 lines (71 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Basic tests for OpenAnalytics API endpoints.
Run with: pytest test_app.py -v
"""
import pytest
from httpx import ASGITransport, AsyncClient
from app import app
@pytest.mark.asyncio
async def test_root_endpoint():
"""Test root endpoint returns service info."""
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
response = await client.get("/")
assert response.status_code == 200
data = response.json()
assert data["service"] == "OpenAnalytics"
assert data["version"] == "2.0.0"
assert data["status"] == "ready"
@pytest.mark.asyncio
async def test_status_endpoint():
"""Test status endpoint returns health status."""
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
response = await client.get("/status")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert "gemini_configured" in data
@pytest.mark.asyncio
async def test_health_check_valid_url():
"""Test health check with valid URL."""
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
response = await client.post("/health", json={"url": "https://example.com"})
assert response.status_code == 200
data = response.json()
assert "score" in data
assert "grade" in data
assert "checks_passed" in data
assert "checks_failed" in data
assert data["checks_passed"] + data["checks_failed"] == 29
assert 0 <= data["score"] <= 100
@pytest.mark.asyncio
async def test_health_check_invalid_url():
"""Test health check with invalid URL returns error."""
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
response = await client.post(
"/health",
json={"url": "https://invalid-url-that-does-not-exist-xyz123.com"}
)
assert response.status_code == 400
assert "Failed to fetch" in response.json()["detail"]
@pytest.mark.asyncio
async def test_mentions_check_valid_input():
"""Test mentions check with valid input."""
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
response = await client.post(
"/mentions",
json={
"company_name": "TestCorp",
"industry": "Technology",
"products": ["Platform"],
"target_audience": "B2B",
"num_queries": 2 # Keep it fast
}
)
assert response.status_code == 200
data = response.json()
assert data["company_name"] == "TestCorp"
assert len(data["queries_generated"]) == 2
assert "visibility" in data
assert "mentions" in data
assert "quality_score" in data
assert 0 <= data["visibility"] <= 100