1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-03 04:25:24 +02:00

Feature/auto increment recipe name (#1088)

* auto-increment-recipe-name

* add test-case

* re-implement as try/except
This commit is contained in:
Hayden 2022-03-23 17:23:40 -08:00 committed by GitHub
parent 0f82523cdd
commit 7f102f513d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 2 deletions

View file

@ -15,6 +15,7 @@ from mealie.services.recipe.recipe_data_service import RecipeDataService
from mealie.services.scraper.scraper_strategies import RecipeScraperOpenGraph
from tests import utils
from tests.utils.app_routes import AppRoutes
from tests.utils.factories import random_string
from tests.utils.fixture_schemas import TestUser
from tests.utils.recipe_data import RecipeSiteTestCase, get_recipe_test_cases
@ -167,3 +168,26 @@ def test_recipe_crud_404(api_client: TestClient, api_routes: AppRoutes, unique_u
response = api_client.patch(api_routes.recipes_create_url, json={"test": "stest"}, headers=unique_user.token)
assert response.status_code == 404
def test_create_recipe_same_name(api_client: TestClient, api_routes: AppRoutes, unique_user: TestUser):
slug = random_string(10)
response = api_client.post("/api/recipes", json={"name": slug}, headers=unique_user.token)
assert response.status_code == 201
assert json.loads(response.text) == slug
response = api_client.post("/api/recipes", json={"name": slug}, headers=unique_user.token)
assert response.status_code == 201
assert json.loads(response.text) == f"{slug}-1"
def test_create_recipe_too_many_time(api_client: TestClient, api_routes: AppRoutes, unique_user: TestUser):
slug = random_string(10)
for _ in range(10):
response = api_client.post("/api/recipes", json={"name": slug}, headers=unique_user.token)
assert response.status_code == 201
response = api_client.post("/api/recipes", json={"name": slug}, headers=unique_user.token)
assert response.status_code == 400

View file

@ -62,9 +62,10 @@ def test_unique_slug_by_group(api_client: TestClient, unique_user: TestUser, g2_
response = api_client.post(Routes.base, json=create_data, headers=g2_user.token)
assert response.status_code == 201
# Try to create a recipe again with the same name
# Try to create a recipe again with the same name and check that the name was incremented
response = api_client.post(Routes.base, json=create_data, headers=g2_user.token)
assert response.status_code == 400
assert response.status_code == 201
assert response.json() == create_data["name"] + "-1"
def test_user_locked_recipe(api_client: TestClient, user_tuple: list[TestUser]) -> None: