feat: expose safe source health status
This commit is contained in:
@@ -12,7 +12,7 @@ from app.database import Base, get_session
|
||||
from app.community_importer import stage_observations
|
||||
from app.importer import ImportAlreadyRunning
|
||||
from app.main import app
|
||||
from app.models import Bait, BaitKind, CatchReport, ExternalEntityAlias, ExternalObservation, Fish, ImportStatus, ModerationEvent, ModerationStatus, OfficialRecordImport, SourceType, Spot, Waterbody
|
||||
from app.models import Bait, BaitKind, CatchReport, DataSource, ExternalEntityAlias, ExternalObservation, Fish, ImportStatus, ModerationEvent, ModerationStatus, OfficialRecordImport, SourceType, Spot, Waterbody
|
||||
|
||||
|
||||
engine = create_engine("sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool)
|
||||
@@ -66,6 +66,17 @@ def test_list_pagination_and_filter_validation() -> None:
|
||||
assert client.get("/api/v1/admin/catch-reports?limit=101", headers=headers).status_code == 422
|
||||
|
||||
|
||||
def test_public_source_status_hides_internal_details() -> None:
|
||||
with Session(engine) as db:
|
||||
if db.get(DataSource, "rf4db") is None:
|
||||
db.add(DataSource(key="rf4db", name="RF4DB", base_url="https://rf4db.com", default_confidence=70, enabled=True))
|
||||
db.commit()
|
||||
response = client.get("/api/v1/source-status")
|
||||
assert response.status_code == 200
|
||||
assert response.json()
|
||||
assert all("error_summary" not in item and "source_url" not in item for item in response.json())
|
||||
|
||||
|
||||
def test_liveness_does_not_probe_dependencies() -> None:
|
||||
response = client.get("/health?token=must-not-be-logged")
|
||||
assert response.json() == {"status": "ok"}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from app.community_scheduler import configured_sources
|
||||
from app.community_scheduler import MAX_BACKOFF_SECONDS, configured_sources, retry_delay
|
||||
from app.config import Settings
|
||||
|
||||
|
||||
@@ -12,3 +12,10 @@ def test_all_authorized_sources_are_scheduled() -> None:
|
||||
def test_community_interval_cannot_be_less_than_30_minutes() -> None:
|
||||
with pytest.raises(ValidationError):
|
||||
Settings(community_import_interval_seconds=1799)
|
||||
|
||||
|
||||
def test_failed_runs_back_off_but_success_resets_delay() -> None:
|
||||
assert retry_delay(["failed"]) == 1800
|
||||
assert retry_delay(["failed", "failed", "failed"]) == 7200
|
||||
assert retry_delay(["failed"] * 20) == MAX_BACKOFF_SECONDS
|
||||
assert retry_delay(["success", "failed"]) == 1800
|
||||
|
||||
Reference in New Issue
Block a user