Reject malformed text imports before creating junk recipes
Co-authored-by: fredamn76 <fredrik.fallman@gmail.com> Signed-off-by: fredamn76 <fredrik.fallman@gmail.com>
This commit is contained in:
@@ -96,6 +96,36 @@ class TestImportReport:
|
||||
assert server._import_report(recipe)["suggested_title"] is None
|
||||
|
||||
|
||||
class TestTextImport:
|
||||
def test_rejects_text_without_explicit_sections_before_writing(self, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
server,
|
||||
"_request",
|
||||
lambda *_args, **_kwargs: pytest.fail("must not create a junk recipe"),
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="Titel"):
|
||||
server.import_recipe_text(
|
||||
"Namnlöst recept\n\nIngredienser:\n1 dl vatten\n\nGör så här:\nBlanda."
|
||||
)
|
||||
|
||||
def test_accepts_the_documented_swedish_section_format(self, monkeypatch):
|
||||
text = (
|
||||
"Titel: Testsoppa\n\nPortioner: 2\n\nIngredienser:\n1 dl vatten\n\n"
|
||||
"Gör så här:\nBlanda."
|
||||
)
|
||||
recipe = {
|
||||
"slug": "testsoppa",
|
||||
"name": "Testsoppa",
|
||||
"recipeIngredient": [{"display": "1 dl vatten"}],
|
||||
"recipeInstructions": [{"text": "Blanda."}],
|
||||
}
|
||||
monkeypatch.setattr(server, "_request", lambda *_args, **_kwargs: "testsoppa")
|
||||
monkeypatch.setattr(server, "get_recipe", lambda _slug: recipe)
|
||||
|
||||
assert server.import_recipe_text(text)["recipe"] == recipe
|
||||
|
||||
|
||||
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