mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 21:45:25 +02:00
* fix #1144 * fix type checks * refactor test routes package * fix #1208 * unify test routes into module
This commit is contained in:
parent
07f6446526
commit
68f7efc177
23 changed files with 189 additions and 148 deletions
|
@ -14,6 +14,7 @@ from mealie.schema.recipe.recipe import RecipeCategory
|
|||
from mealie.services.recipe.recipe_data_service import RecipeDataService
|
||||
from mealie.services.scraper.scraper_strategies import RecipeScraperOpenGraph
|
||||
from tests import data, utils
|
||||
from tests.utils import routes
|
||||
from tests.utils.app_routes import AppRoutes
|
||||
from tests.utils.factories import random_string
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
@ -157,12 +158,11 @@ def test_create_by_url_with_tags(
|
|||
@pytest.mark.parametrize("recipe_data", recipe_test_data)
|
||||
def test_read_update(
|
||||
api_client: TestClient,
|
||||
api_routes: AppRoutes,
|
||||
recipe_data: RecipeSiteTestCase,
|
||||
unique_user: TestUser,
|
||||
recipe_categories: list[RecipeCategory],
|
||||
):
|
||||
recipe_url = api_routes.recipes_recipe_slug(recipe_data.expected_slug)
|
||||
recipe_url = routes.recipes.Recipe.item(recipe_data.expected_slug)
|
||||
response = api_client.get(recipe_url, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
@ -196,8 +196,8 @@ def test_read_update(
|
|||
|
||||
|
||||
@pytest.mark.parametrize("recipe_data", recipe_test_data)
|
||||
def test_rename(api_client: TestClient, api_routes: AppRoutes, recipe_data: RecipeSiteTestCase, unique_user: TestUser):
|
||||
recipe_url = api_routes.recipes_recipe_slug(recipe_data.expected_slug)
|
||||
def test_rename(api_client: TestClient, recipe_data: RecipeSiteTestCase, unique_user: TestUser):
|
||||
recipe_url = routes.recipes.Recipe.item(recipe_data.expected_slug)
|
||||
response = api_client.get(recipe_url, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
@ -215,44 +215,66 @@ def test_rename(api_client: TestClient, api_routes: AppRoutes, recipe_data: Reci
|
|||
|
||||
|
||||
@pytest.mark.parametrize("recipe_data", recipe_test_data)
|
||||
def test_delete(api_client: TestClient, api_routes: AppRoutes, recipe_data: RecipeSiteTestCase, unique_user: TestUser):
|
||||
recipe_url = api_routes.recipes_recipe_slug(recipe_data.expected_slug)
|
||||
response = api_client.delete(recipe_url, headers=unique_user.token)
|
||||
def test_delete(api_client: TestClient, recipe_data: RecipeSiteTestCase, unique_user: TestUser):
|
||||
response = api_client.delete(routes.recipes.Recipe.item(recipe_data.expected_slug), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_recipe_crud_404(api_client: TestClient, api_routes: AppRoutes, unique_user: TestUser):
|
||||
response = api_client.put(api_routes.recipes_recipe_slug("test"), json={"test": "stest"}, headers=unique_user.token)
|
||||
response = api_client.put(routes.recipes.Recipe.item("test"), json={"test": "stest"}, headers=unique_user.token)
|
||||
assert response.status_code == 404
|
||||
|
||||
response = api_client.get(api_routes.recipes_recipe_slug("test"), headers=unique_user.token)
|
||||
response = api_client.get(routes.recipes.Recipe.item("test"), headers=unique_user.token)
|
||||
assert response.status_code == 404
|
||||
|
||||
response = api_client.delete(api_routes.recipes_recipe_slug("test"), headers=unique_user.token)
|
||||
response = api_client.delete(routes.recipes.Recipe.item("test"), headers=unique_user.token)
|
||||
assert response.status_code == 404
|
||||
|
||||
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):
|
||||
def test_create_recipe_same_name(api_client: TestClient, unique_user: TestUser):
|
||||
slug = random_string(10)
|
||||
|
||||
response = api_client.post("/api/recipes", json={"name": slug}, headers=unique_user.token)
|
||||
response = api_client.post(routes.recipes.Recipe.base, 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)
|
||||
response = api_client.post(routes.recipes.Recipe.base, 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):
|
||||
def test_create_recipe_too_many_time(api_client: TestClient, unique_user: TestUser):
|
||||
slug = random_string(10)
|
||||
|
||||
for _ in range(10):
|
||||
response = api_client.post("/api/recipes", json={"name": slug}, headers=unique_user.token)
|
||||
response = api_client.post(routes.recipes.Recipe.base, 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)
|
||||
response = api_client.post(routes.recipes.Recipe.base, json={"name": slug}, headers=unique_user.token)
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_delete_recipe_same_name(api_client: TestClient, unique_user: utils.TestUser, g2_user: utils.TestUser):
|
||||
slug = random_string(10)
|
||||
|
||||
# Create recipe for both users
|
||||
for user in (unique_user, g2_user):
|
||||
response = api_client.post(routes.recipes.Recipe.base, json={"name": slug}, headers=user.token)
|
||||
assert response.status_code == 201
|
||||
assert json.loads(response.text) == slug
|
||||
|
||||
# Delete recipe for user 1
|
||||
response = api_client.delete(routes.recipes.Recipe.item(slug), headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Ensure recipe for user 2 still exists
|
||||
response = api_client.get(routes.recipes.Recipe.item(slug), headers=g2_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Make sure recipe for user 1 doesn't exist
|
||||
response = api_client.get(routes.recipes.Recipe.item(slug), headers=unique_user.token)
|
||||
response = api_client.get(routes.recipes.Recipe.item(slug), headers=unique_user.token)
|
||||
assert response.status_code == 404
|
||||
|
|
|
@ -26,7 +26,7 @@ def test_associate_ingredient_with_step(api_client: TestClient, unique_user: Tes
|
|||
steps[idx] = [str(ingredient.reference_id) for ingredient in ingredients]
|
||||
|
||||
response = api_client.put(
|
||||
routes.RoutesRecipe.item(recipe.slug),
|
||||
routes.recipes.Recipe.item(recipe.slug),
|
||||
json=jsonify(recipe.dict()),
|
||||
headers=unique_user.token,
|
||||
)
|
||||
|
@ -35,14 +35,14 @@ def test_associate_ingredient_with_step(api_client: TestClient, unique_user: Tes
|
|||
|
||||
# Get Recipe and check that the ingredient is associated with the step
|
||||
|
||||
response = api_client.get(routes.RoutesRecipe.item(recipe.slug), headers=unique_user.token)
|
||||
response = api_client.get(routes.recipes.Recipe.item(recipe.slug), headers=unique_user.token)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
recipe = json.loads(response.text)
|
||||
data: dict = json.loads(response.text)
|
||||
|
||||
for idx, step in enumerate(recipe.get("recipeInstructions")):
|
||||
all_refs = [ref["referenceId"] for ref in step.get("ingredientReferences")]
|
||||
for idx, stp in enumerate(data.get("recipeInstructions")):
|
||||
all_refs = [ref["referenceId"] for ref in stp.get("ingredientReferences")]
|
||||
|
||||
assert len(all_refs) == 2
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue