feat: check source links during scheduled fetches

This commit is contained in:
ik
2026-09-13 16:32:10 +07:00
parent bc3ceb5dfe
commit 1305cccfa5
6 changed files with 110 additions and 7 deletions
+30 -1
View File
@@ -9,7 +9,7 @@ from sqlalchemy.orm import Session
from app.community_importer import CommunityImportError, stage_observations
from app.community_review import ExternalReviewError, map_observation, publish_observation, suggest_aliases
from app.source_lifecycle import record_source_check
from app.source_lifecycle import record_scheduled_source_check, record_source_check
from app.database import Base
from app.models import CatchReport, DataSource, ExternalEntityAlias, ExternalObservation, Fish, Waterbody
from rf4_research.community_sources import parse_rf4db_catches, parse_rf4map_point, parse_rf4posts_spot
@@ -186,6 +186,35 @@ def test_non_authoritative_source_failures_do_not_withdraw(db: Session, status:
assert item.source_check_status == status
def test_scheduled_failure_only_affects_exact_source_url(db: Session) -> None:
stage_observations(db, [
record(external_id="matching"),
record(external_id="other") | {"source_url": "https://rf4db.com/catches/other"},
])
affected = record_scheduled_source_check(
db,
source_system="rf4db",
source_url="https://rf4db.com/ru/catches/matching",
status="missing",
)
items = {item.source_external_id: item for item in db.scalars(select(ExternalObservation))}
assert affected == 1
assert items["matching"].status == "withdrawn"
assert items["other"].status != "withdrawn"
assert items["other"].source_check_status == "available"
record_scheduled_source_check(
db,
source_system="rf4db",
source_url="https://rf4db.com/ru/catches/matching",
status="available",
)
assert items["matching"].source_check_status == "available"
assert items["matching"].status == "withdrawn"
def test_auto_publication_requires_enabled_source(db: Session) -> None:
source = DataSource(key="rf4db", name="RF4DB", base_url="https://rf4db.com", default_confidence=70, enabled=False)
fish = Fish(slug="pike", name_ru="Щука")