Public Access
feat: orchestrator step_scrape with retry + stale-data fallback
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -168,3 +168,40 @@ def test_send_admin_alert_calls_backend(monkeypatch):
|
||||
assert len(sent) == 1
|
||||
assert "[MealPlanner ALERT] boom" in sent[0]["subject"]
|
||||
assert sent[0]["to"] == "admin@example.com"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# step_scrape tests
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_step_scrape_idempotent(db, weekly_run_scraped):
|
||||
original_ts = weekly_run_scraped.scraped_at
|
||||
from app.services.orchestrator.steps import step_scrape
|
||||
step_scrape(weekly_run_scraped, db)
|
||||
assert weekly_run_scraped.scraped_at == original_ts
|
||||
|
||||
|
||||
def test_step_scrape_success(db, weekly_run, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"app.services.orchestrator.steps.ScraperService.run_scrape",
|
||||
lambda self, **kw: {"status": "success", "items_scraped": 42},
|
||||
)
|
||||
from app.services.orchestrator.steps import step_scrape
|
||||
step_scrape(weekly_run, db)
|
||||
assert weekly_run.scraped_at is not None
|
||||
assert weekly_run.used_stale_data is False
|
||||
|
||||
|
||||
def test_step_scrape_both_fail_marks_stale(db, weekly_run, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"app.services.orchestrator.steps.ScraperService.run_scrape",
|
||||
lambda self, **kw: {"status": "failed", "error": "timeout"},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"app.services.orchestrator.steps.send_admin_alert",
|
||||
lambda subject, body: None,
|
||||
)
|
||||
from app.services.orchestrator.steps import step_scrape
|
||||
step_scrape(weekly_run, db)
|
||||
assert weekly_run.used_stale_data is True
|
||||
assert weekly_run.scraped_at is not None
|
||||
|
||||
Reference in New Issue
Block a user