|
18 | 18 |
|
19 | 19 | from mealie.repos.repository_factory import AllRepositories
|
20 | 20 | from mealie.schema.recipe.recipe import RecipeCategory, RecipeSummary, RecipeTag
|
| 21 | +from mealie.schema.recipe.recipe_notes import RecipeNote |
21 | 22 | from mealie.services.recipe.recipe_data_service import RecipeDataService
|
22 | 23 | from mealie.services.scraper.recipe_scraper import DEFAULT_SCRAPER_STRATEGIES
|
23 | 24 | from tests import data, utils
|
@@ -610,6 +611,42 @@ def test_rename(api_client: TestClient, recipe_data: RecipeSiteTestCase, unique_
|
610 | 611 | recipe_data.expected_slug = new_slug
|
611 | 612 |
|
612 | 613 |
|
| 614 | +def test_remove_notes(api_client: TestClient, unique_user: TestUser): |
| 615 | + # create recipe |
| 616 | + recipe_create_url = api_routes.recipes |
| 617 | + recipe_create_data = {"name": random_string()} |
| 618 | + response = api_client.post(recipe_create_url, headers=unique_user.token, json=recipe_create_data) |
| 619 | + assert response.status_code == 201 |
| 620 | + recipe_slug: str = response.json() |
| 621 | + |
| 622 | + # get recipe and add a note |
| 623 | + recipe_url = api_routes.recipes_slug(recipe_slug) |
| 624 | + response = api_client.get(recipe_url, headers=unique_user.token) |
| 625 | + assert response.status_code == 200 |
| 626 | + |
| 627 | + recipe = json.loads(response.text) |
| 628 | + recipe["notes"] = [RecipeNote(title=random_string(), text=random_string()).dict()] |
| 629 | + response = api_client.put(recipe_url, json=recipe, headers=unique_user.token) |
| 630 | + assert response.status_code == 200 |
| 631 | + |
| 632 | + # get recipe and remove the note |
| 633 | + response = api_client.get(recipe_url, headers=unique_user.token) |
| 634 | + assert response.status_code == 200 |
| 635 | + |
| 636 | + recipe = json.loads(response.text) |
| 637 | + assert len(recipe.get("notes", [])) == 1 |
| 638 | + recipe["notes"] = [] |
| 639 | + response = api_client.put(recipe_url, json=recipe, headers=unique_user.token) |
| 640 | + assert response.status_code == 200 |
| 641 | + |
| 642 | + # verify the note is removed |
| 643 | + response = api_client.get(recipe_url, headers=unique_user.token) |
| 644 | + assert response.status_code == 200 |
| 645 | + |
| 646 | + recipe = json.loads(response.text) |
| 647 | + assert len(recipe.get("notes", [])) == 0 |
| 648 | + |
| 649 | + |
613 | 650 | @pytest.mark.parametrize("recipe_data", recipe_test_data)
|
614 | 651 | def test_delete(api_client: TestClient, recipe_data: RecipeSiteTestCase, unique_user: TestUser):
|
615 | 652 | response = api_client.delete(api_routes.recipes_slug(recipe_data.expected_slug), headers=unique_user.token)
|
|
0 commit comments