mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-03 09:04:06 -05:00
feat: Add DELETE /{slug}/image (#6259)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
7bb0f0801a
commit
bb67d993a0
@@ -6,6 +6,7 @@ from fastapi.testclient import TestClient
|
||||
from mealie.repos.repository_factory import AllRepositories
|
||||
from mealie.schema.recipe.recipe import Recipe
|
||||
from mealie.schema.recipe.recipe_settings import RecipeSettings
|
||||
from mealie.services.recipe.recipe_service import RecipeDataService
|
||||
from tests import data
|
||||
from tests.utils import api_routes
|
||||
from tests.utils.factories import random_string
|
||||
@@ -211,3 +212,50 @@ def test_user_can_update_recipe_image(api_client: TestClient, unique_user: TestU
|
||||
response = api_client.get(api_routes.recipes_slug(recipe_id), headers=unique_user.token)
|
||||
recipe_respons = response.json()
|
||||
assert recipe_respons["image"] is not None
|
||||
|
||||
service = RecipeDataService(recipe_json.id)
|
||||
assert service.dir_image.exists() and any(f.is_file() for f in service.dir_image.iterdir())
|
||||
|
||||
|
||||
def test_user_can_delete_recipe_image(api_client: TestClient, unique_user: TestUser):
|
||||
data_payload = {"extension": "jpg"}
|
||||
file_payload = {"image": data.images_test_image_1.read_bytes()}
|
||||
|
||||
household = unique_user.repos.households.get_one(unique_user.household_id)
|
||||
assert household and household.preferences
|
||||
household.preferences.private_household = True
|
||||
household.preferences.lock_recipe_edits_from_other_households = True
|
||||
unique_user.repos.household_preferences.update(household.id, household.preferences)
|
||||
|
||||
response = api_client.post(api_routes.recipes, json={"name": random_string()}, headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
recipe_json = unique_user.repos.recipes.get_one(response.json())
|
||||
assert recipe_json and recipe_json.id
|
||||
assert recipe_json.image is None
|
||||
recipe_id = str(recipe_json.id)
|
||||
|
||||
response = api_client.put(
|
||||
api_routes.recipes_slug_image(recipe_json.slug),
|
||||
data=data_payload,
|
||||
files=file_payload,
|
||||
headers=unique_user.token,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = api_client.get(api_routes.recipes_slug(recipe_id), headers=unique_user.token)
|
||||
recipe_respons = response.json()
|
||||
assert recipe_respons["image"] is not None
|
||||
|
||||
service = RecipeDataService(recipe_json.id)
|
||||
assert service.dir_image.exists() and any(f.is_file() for f in service.dir_image.iterdir())
|
||||
|
||||
response = api_client.delete(
|
||||
api_routes.recipes_slug_image(recipe_json.slug),
|
||||
headers=unique_user.token,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = api_client.get(api_routes.recipes_slug(recipe_id), headers=unique_user.token)
|
||||
recipe_respons = response.json()
|
||||
assert recipe_respons["image"] is None
|
||||
assert not service.dir_image.exists() or not any(f.is_file() for f in service.dir_image.iterdir())
|
||||
|
||||
Reference in New Issue
Block a user