recetas Fase B: modelo ampliado (pasos/notas/categoría/autoría/linaje/visibilidad), migración idempotente ALTER, publicar guarda todo, buscar solo públicas, endpoint /cookbook/{author_id}
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
49
test_recipes.py
Normal file
49
test_recipes.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Tests de recetas (Fase B): publicar con campos nuevos, buscar solo públicas,
|
||||
obtener por id y cookbook por autor. SQLite en memoria."""
|
||||
import os
|
||||
|
||||
os.environ["DATABASE_URL"] = "sqlite://"
|
||||
|
||||
from fastapi.testclient import TestClient # noqa: E402
|
||||
|
||||
from main import app # noqa: E402
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_publicar_y_obtener_con_campos_nuevos():
|
||||
body = {
|
||||
"id": "r1", "name": "Flan", "servings": 4,
|
||||
"items": [], "steps": ["Bate", "Hornea"], "notes": "de la abuela",
|
||||
"category": "postres", "prepMinutes": 30,
|
||||
"authorId": "auth-1", "authorName": "Carlos",
|
||||
"visibility": "public", "deviceToken": "dev-1",
|
||||
}
|
||||
r = client.post("/recipes", json=body)
|
||||
assert r.status_code < 300, r.text
|
||||
got = client.get("/recipes/r1").json()
|
||||
assert got["steps"] == ["Bate", "Hornea"]
|
||||
assert got["category"] == "postres"
|
||||
assert got["prepMinutes"] == 30
|
||||
assert got["notes"] == "de la abuela"
|
||||
assert got["authorName"] == "Carlos"
|
||||
assert got["visibility"] == "public"
|
||||
|
||||
|
||||
def test_buscar_solo_publicas_y_cookbook():
|
||||
client.post("/recipes", json={"id": "pub", "name": "Pública", "servings": 1,
|
||||
"items": [], "visibility": "public", "authorId": "a1"})
|
||||
client.post("/recipes", json={"id": "prv", "name": "Privada", "servings": 1,
|
||||
"items": [], "visibility": "private", "authorId": "a1"})
|
||||
names = [x["name"] for x in client.get("/recipes?q=").json()]
|
||||
assert "Pública" in names
|
||||
assert "Privada" not in names
|
||||
ids = {x["id"] for x in client.get("/cookbook/a1").json()}
|
||||
assert ids == {"pub", "prv"}
|
||||
|
||||
|
||||
def test_receta_anonima_sin_nombre():
|
||||
client.post("/recipes", json={"id": "anon", "name": "Anón", "servings": 1,
|
||||
"items": [], "visibility": "public", "authorId": "a2"})
|
||||
got = client.get("/recipes/anon").json()
|
||||
assert got["authorName"] is None
|
||||
Reference in New Issue
Block a user