Redesign test framework: fix conftest, rewrite all tests, fix model index conflicts, fix black formatting
Agent-Logs-Url: https://github.com/christianlouis/dmarq/sessions/9d256101-34b6-4861-a8cf-7f86f32b54d5 Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
from app.models.domain import Domain
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
def test_read_health(client: TestClient):
|
||||
"""Test health check endpoint"""
|
||||
def test_health_check(client: TestClient):
|
||||
"""Test the health check endpoint returns status ok."""
|
||||
response = client.get("/api/v1/health")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
@@ -12,47 +10,29 @@ def test_read_health(client: TestClient):
|
||||
assert "version" in data
|
||||
|
||||
|
||||
def test_read_domains_empty(client: TestClient):
|
||||
"""Test reading domains when none exist"""
|
||||
response = client.get("/api/v1/domains")
|
||||
def test_domains_empty(client: TestClient):
|
||||
"""Test that GET /api/v1/domains/domains returns empty list when no reports uploaded."""
|
||||
response = client.get("/api/v1/domains/domains")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data == []
|
||||
|
||||
|
||||
def test_read_domains(client: TestClient, db_session: Session):
|
||||
"""Test reading domains"""
|
||||
# Create some test domains
|
||||
domain1 = Domain(name="example.com", description="Example Domain", active=True)
|
||||
domain2 = Domain(name="test.com", description="Test Domain", active=True)
|
||||
db_session.add_all([domain1, domain2])
|
||||
db_session.commit()
|
||||
|
||||
response = client.get("/api/v1/domains")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
assert len(data) == 2
|
||||
assert {"name": "example.com", "description": "Example Domain"}.items() <= data[0].items()
|
||||
assert {"name": "test.com", "description": "Test Domain"}.items() <= data[1].items()
|
||||
|
||||
|
||||
def test_create_domain(client: TestClient):
|
||||
"""Test creating a new domain"""
|
||||
def test_reports_upload_invalid_extension(client: TestClient):
|
||||
"""Test that uploading a file with an unsupported extension returns 400."""
|
||||
response = client.post(
|
||||
"/api/v1/domains",
|
||||
json={"name": "newdomain.com", "description": "New Domain", "active": True},
|
||||
"/api/v1/reports/upload",
|
||||
files={"file": ("report.txt", b"not a report", "text/plain")},
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert "Invalid file type" in response.json()["detail"]
|
||||
|
||||
assert response.status_code == 201
|
||||
data = response.json()
|
||||
assert data["name"] == "newdomain.com"
|
||||
assert data["description"] == "New Domain"
|
||||
assert data["active"] is True
|
||||
assert "id" in data
|
||||
|
||||
# Check that the domain was actually created
|
||||
response = client.get("/api/v1/domains")
|
||||
assert response.status_code == 200
|
||||
domains = response.json()
|
||||
assert any(d["name"] == "newdomain.com" for d in domains)
|
||||
def test_reports_upload_empty_file(client: TestClient):
|
||||
"""Test that uploading an empty file returns 400."""
|
||||
response = client.post(
|
||||
"/api/v1/reports/upload",
|
||||
files={"file": ("report.xml", b"", "application/xml")},
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert "empty" in response.json()["detail"].lower()
|
||||
|
||||
Reference in New Issue
Block a user