Public Access
76 lines
2.3 KiB
Python
76 lines
2.3 KiB
Python
"""Regression tests for retired direct third-party acquisition endpoints."""
|
|
from types import SimpleNamespace
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
|
|
pytestmark = pytest.mark.requires_postgres
|
|
|
|
|
|
def _login(client):
|
|
response = client.post("/api/auth/login", json={"password": "test-family-password"})
|
|
assert response.status_code == 204, response.text
|
|
|
|
|
|
def test_direct_recipe_search_and_import_are_gone(client):
|
|
_login(client)
|
|
|
|
search = client.get("/api/recipes/search", params={"q": "apple", "limit": 5})
|
|
assert search.status_code == 410
|
|
assert "staged and approved" in search.json()["detail"]
|
|
|
|
imported = client.post(
|
|
"/api/recipes/import",
|
|
json={"external_id": "123", "external_source": "spoonacular"},
|
|
)
|
|
assert imported.status_code == 410
|
|
assert "staged and approved" in imported.json()["detail"]
|
|
|
|
|
|
def test_admin_discovery_stages_without_publishing(client, db, monkeypatch):
|
|
from app.models import FamilyProfile, Recipe, RecipeImportStatus
|
|
|
|
family = FamilyProfile(
|
|
name=f"Staging Family {uuid4()}",
|
|
household_size=2,
|
|
adult_count=2,
|
|
child_count=0,
|
|
)
|
|
db.add(family)
|
|
db.flush()
|
|
analysis = SimpleNamespace(
|
|
discovery_queries=["apple dinner"],
|
|
confidence=0.9,
|
|
)
|
|
analysis.to_dict = lambda: {
|
|
"discovery_queries": analysis.discovery_queries,
|
|
"confidence": analysis.confidence,
|
|
}
|
|
monkeypatch.setattr(
|
|
"app.api.admin.FeedbackAnalyzer.analyze",
|
|
lambda self, database, family_id: analysis,
|
|
)
|
|
staged = [
|
|
SimpleNamespace(status=RecipeImportStatus.PENDING),
|
|
SimpleNamespace(status=RecipeImportStatus.QUARANTINED),
|
|
]
|
|
monkeypatch.setattr(
|
|
"app.api.admin.WikibooksImportService.stage_discovered_pages",
|
|
lambda self, database, limit, queries: staged,
|
|
)
|
|
before = db.query(Recipe).count()
|
|
|
|
response = client.post(
|
|
"/api/admin/trigger-discovery",
|
|
params={"family_profile_id": str(family.id), "limit": 2},
|
|
headers={"Authorization": "Bearer test-admin-token"},
|
|
)
|
|
|
|
assert response.status_code == 200, response.text
|
|
assert response.json()["candidates_staged"] == 2
|
|
assert response.json()["pending"] == 1
|
|
assert response.json()["quarantined"] == 1
|
|
assert response.json()["recipes_added"] == 0
|
|
assert db.query(Recipe).count() == before
|