Add verified rollback for failed recipe imports
Co-authored-by: Bumble <bumble@agents.famfallman.com> Co-authored-by: fredamn76 <fredrik.fallman@gmail.com> Signed-off-by: fredamn76 <fredrik.fallman@gmail.com>
This commit is contained in:
@@ -126,6 +126,48 @@ class TestTextImport:
|
||||
assert server.import_recipe_text(text)["recipe"] == recipe
|
||||
|
||||
|
||||
class TestDeleteRecipe:
|
||||
def test_requires_the_exact_stored_slug(self, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
server,
|
||||
"get_recipe",
|
||||
lambda _slug: {"slug": "stored-slug", "name": "Test"},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
server,
|
||||
"_client",
|
||||
lambda: pytest.fail("must not delete without exact confirmation"),
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="stored-slug"):
|
||||
server.delete_recipe("recipe-id", "wrong-slug")
|
||||
|
||||
def test_deletes_and_proves_the_recipe_is_gone(self, mock_mealie):
|
||||
recipe = {"slug": "zzz-test", "name": "ZZZ Test"}
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
if request.method == "DELETE":
|
||||
return httpx.Response(200, json={})
|
||||
if request.url.path == "/api/recipes/zzz-test":
|
||||
# First GET is get_recipe; second GET is the deletion proof.
|
||||
if getattr(handler, "read_once", False):
|
||||
return httpx.Response(404, json={"detail": "Not Found"})
|
||||
handler.read_once = True
|
||||
return httpx.Response(200, json=recipe)
|
||||
return httpx.Response(500)
|
||||
|
||||
mock_mealie(handler)
|
||||
result = server.delete_recipe("zzz-test", "zzz-test")
|
||||
|
||||
assert result == {
|
||||
"deleted": True,
|
||||
"slug": "zzz-test",
|
||||
"name": "ZZZ Test",
|
||||
"delete_status": 200,
|
||||
"readback_status": 404,
|
||||
}
|
||||
|
||||
|
||||
class TestParseIngredients:
|
||||
def test_reverts_structure_when_mealie_rewords_the_swedish_line(self, mock_mealie):
|
||||
canonical = "4,7 dl basmatiris"
|
||||
|
||||
Reference in New Issue
Block a user