feat: add operations health and domain setup polish
This commit is contained in:
@@ -18,6 +18,42 @@ def test_domains_empty(client: TestClient):
|
||||
assert data == []
|
||||
|
||||
|
||||
def test_create_domain_without_reports(authed_client: TestClient):
|
||||
"""A monitored domain can be created before its first report arrives."""
|
||||
response = authed_client.post(
|
||||
"/api/v1/domains/domains",
|
||||
json={"name": "Example.COM.", "description": "Primary mail domain"},
|
||||
)
|
||||
assert response.status_code == 201
|
||||
assert response.json()["name"] == "example.com"
|
||||
|
||||
list_response = authed_client.get("/api/v1/domains/domains")
|
||||
assert list_response.status_code == 200
|
||||
assert list_response.json()[0]["name"] == "example.com"
|
||||
assert list_response.json()[0]["reports_count"] == 0
|
||||
|
||||
|
||||
def test_create_domain_rejects_duplicates(authed_client: TestClient):
|
||||
"""Creating the same monitored domain twice returns a conflict."""
|
||||
first = authed_client.post("/api/v1/domains/domains", json={"name": "example.com"})
|
||||
second = authed_client.post("/api/v1/domains/domains", json={"name": "EXAMPLE.com"})
|
||||
|
||||
assert first.status_code == 201
|
||||
assert second.status_code == 409
|
||||
|
||||
|
||||
def test_operations_health_endpoint(authed_client: TestClient):
|
||||
"""Detailed health includes database, scheduler, import, and report sections."""
|
||||
response = authed_client.get("/api/v1/health/operations")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["service"] == "dmarq"
|
||||
assert data["database"]["ok"] is True
|
||||
assert "scheduler" in data
|
||||
assert "imports" in data
|
||||
assert "reports" in data
|
||||
|
||||
|
||||
def test_reports_upload_invalid_extension(client: TestClient):
|
||||
"""Test that uploading a file with an unsupported extension returns 400."""
|
||||
response = client.post(
|
||||
|
||||
@@ -3,6 +3,7 @@ from email.header import Header
|
||||
from email.mime.application import MIMEApplication
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from typing import Optional
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -60,7 +61,7 @@ def _raw_email_with_report() -> bytes:
|
||||
|
||||
|
||||
def _raw_email_with_attachment(
|
||||
filename: str | None,
|
||||
filename: Optional[str],
|
||||
content: bytes,
|
||||
subtype: str = "octet-stream",
|
||||
subject: str = "DMARC report",
|
||||
|
||||
Reference in New Issue
Block a user