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

fix: Fix file not found error with individual recipe export/download. (#3579)

This commit is contained in:
nephlm 2024-05-20 18:53:14 -04:00 committed by GitHub
parent c610ec1344
commit c70a5cb72c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 115 additions and 80 deletions

View file

@ -1,3 +1,7 @@
from io import BytesIO
import json
import zipfile
from fastapi.testclient import TestClient
from tests.utils import api_routes
@ -36,6 +40,29 @@ def test_render_jinja_template(api_client: TestClient, unique_user: TestUser) ->
assert f"# {recipe_name}" in response.text
def test_get_recipe_as_zip(api_client: TestClient, unique_user: TestUser) -> None:
# Create Recipe
recipe_name = random_string()
response = api_client.post(api_routes.recipes, json={"name": recipe_name}, headers=unique_user.token)
assert response.status_code == 201
slug = response.json()
# Get zip token
response = api_client.post(api_routes.recipes_slug_exports(slug), headers=unique_user.token)
assert response.status_code == 200
token = response.json()["token"]
assert token
response = api_client.get(api_routes.recipes_slug_exports_zip(slug) + f"?token={token}", headers=unique_user.token)
assert response.status_code == 200
# Verify the zip
zip_file = BytesIO(response.content)
with zipfile.ZipFile(zip_file, "r") as zip_fp:
with zip_fp.open(f"{slug}.json") as json_fp:
assert json.loads(json_fp.read())["name"] == recipe_name
# TODO: Allow users to upload templates to their own directory
# def test_upload_template(api_client: TestClient, unique_user: TestUser) -> None:
# assert False