mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
restructure test folder
This commit is contained in:
parent
75a986ab17
commit
0b1db28fdd
26 changed files with 55 additions and 42 deletions
|
@ -8,34 +8,53 @@ def cleanup(api_client):
|
|||
api_client.delete(f"/api/recipe/{recipe_test_data[1].expected_slug}/delete/")
|
||||
|
||||
|
||||
meal_plan = {
|
||||
"startDate": "2021-01-18",
|
||||
"endDate": "2021-01-19",
|
||||
"meals": [
|
||||
{
|
||||
"slug": None,
|
||||
"date": "2021-1-17",
|
||||
"dateText": "Monday, January 18, 2021",
|
||||
},
|
||||
{
|
||||
"slug": None,
|
||||
"date": "2021-1-18",
|
||||
"dateText": "Tueday, January 19, 2021",
|
||||
},
|
||||
],
|
||||
}
|
||||
def get_meal_plan_template(first=None, second=None):
|
||||
return {
|
||||
"startDate": "2021-01-18",
|
||||
"endDate": "2021-01-19",
|
||||
"meals": [
|
||||
{
|
||||
"slug": first,
|
||||
"date": "2021-1-17",
|
||||
"dateText": "Monday, January 18, 2021",
|
||||
},
|
||||
{
|
||||
"slug": second,
|
||||
"date": "2021-1-18",
|
||||
"dateText": "Tueday, January 19, 2021",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
slug_1 = None
|
||||
slug_2 = None
|
||||
|
||||
|
||||
def get_slugs(api_client):
|
||||
# Slug 1
|
||||
global slug_1
|
||||
global slug_2
|
||||
if slug_1 == None:
|
||||
slug_1 = api_client.post(
|
||||
"/api/recipe/create-url/", json={"url": recipe_test_data[0].url}
|
||||
)
|
||||
slug_1 = json.loads(slug_1.content)
|
||||
|
||||
# Slug 2
|
||||
slug_2 = api_client.post(
|
||||
"/api/recipe/create-url/", json={"url": recipe_test_data[1].url}
|
||||
)
|
||||
slug_2 = json.loads(slug_2.content)
|
||||
|
||||
return slug_1, slug_2
|
||||
|
||||
|
||||
def test_create_mealplan(api_client):
|
||||
slug_1 = api_client.post(
|
||||
"/api/recipe/create-url/", json={"url": recipe_test_data[0].url}
|
||||
)
|
||||
slug_2 = api_client.post(
|
||||
"/api/recipe/create-url/", json={"url": recipe_test_data[1].url}
|
||||
)
|
||||
|
||||
meal_plan["meals"][0]["slug"] = json.loads(slug_1.content)
|
||||
meal_plan["meals"][1]["slug"] = json.loads(slug_2.content)
|
||||
slug_1, slug_2 = get_slugs(api_client)
|
||||
meal_plan = get_meal_plan_template()
|
||||
meal_plan["meals"][0]["slug"] = slug_1
|
||||
meal_plan["meals"][1]["slug"] = slug_2
|
||||
|
||||
response = api_client.post("/api/meal-plan/create/", json=meal_plan)
|
||||
assert response.status_code == 200
|
||||
|
@ -46,22 +65,18 @@ def test_read_mealplan(api_client):
|
|||
|
||||
assert response.status_code == 200
|
||||
|
||||
slug_1, slug_2 = get_slugs(api_client)
|
||||
meal_plan = get_meal_plan_template(slug_1, slug_2)
|
||||
|
||||
new_meal_plan = json.loads(response.text)
|
||||
meals = new_meal_plan[0]["meals"]
|
||||
|
||||
assert meals[0]["slug"] == meal_plan["meals"][0]["slug"]
|
||||
assert meals[1]["slug"] == meal_plan["meals"][1]["slug"]
|
||||
|
||||
cleanup(api_client)
|
||||
|
||||
|
||||
def test_update_mealplan(api_client):
|
||||
slug_1 = api_client.post(
|
||||
"/api/recipe/create-url/", json={"url": recipe_test_data[0].url}
|
||||
)
|
||||
slug_2 = api_client.post(
|
||||
"/api/recipe/create-url/", json={"url": recipe_test_data[1].url}
|
||||
)
|
||||
slug_1, slug_2 = get_slugs(api_client)
|
||||
|
||||
response = api_client.get("/api/meal-plan/all/")
|
||||
|
||||
|
@ -70,8 +85,8 @@ def test_update_mealplan(api_client):
|
|||
|
||||
## Swap
|
||||
plan_uid = existing_mealplan.get("uid")
|
||||
existing_mealplan["meals"][0]["slug"] = json.loads(slug_2.content)
|
||||
existing_mealplan["meals"][1]["slug"] = json.loads(slug_1.content)
|
||||
existing_mealplan["meals"][0]["slug"] = slug_2
|
||||
existing_mealplan["meals"][1]["slug"] = slug_1
|
||||
|
||||
response = api_client.post(
|
||||
f"/api/meal-plan/{plan_uid}/update/", json=existing_mealplan
|
||||
|
@ -83,10 +98,8 @@ def test_update_mealplan(api_client):
|
|||
existing_mealplan = json.loads(response.text)
|
||||
existing_mealplan = existing_mealplan[0]
|
||||
|
||||
assert existing_mealplan["meals"][0]["slug"] == json.loads(slug_2.content)
|
||||
assert existing_mealplan["meals"][1]["slug"] == json.loads(slug_1.content)
|
||||
|
||||
cleanup(api_client)
|
||||
assert existing_mealplan["meals"][0]["slug"] == slug_2
|
||||
assert existing_mealplan["meals"][1]["slug"] == slug_1
|
||||
|
||||
|
||||
def test_delete_mealplan(api_client):
|
||||
|
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
@ -11,7 +11,7 @@ from services.migrations.nextcloud import (
|
|||
from services.recipe_services import Recipe
|
||||
|
||||
CWD = Path(__file__).parent
|
||||
NEXTCLOUD_DIR = CWD.parent.joinpath("data", "nextcloud_recipes")
|
||||
NEXTCLOUD_DIR = CWD.joinpath("data", "nextcloud_recipes")
|
||||
TEMP_NEXTCLOUD = TEMP_DIR.joinpath("nextcloud")
|
||||
|
||||
|
0
mealie/tests/test_services/test_scraper/__init__.py
Normal file
0
mealie/tests/test_services/test_scraper/__init__.py
Normal file
|
@ -10,8 +10,8 @@ from services.scrape_services import (
|
|||
)
|
||||
|
||||
CWD = Path(__file__).parent
|
||||
RAW_RECIPE_DIR = CWD.parent.joinpath("data", "recipes-raw")
|
||||
RAW_HTML_DIR = CWD.parent.joinpath("data", "html-raw")
|
||||
RAW_RECIPE_DIR = CWD.joinpath("data", "recipes-raw")
|
||||
RAW_HTML_DIR = CWD.joinpath("data", "html-raw")
|
||||
|
||||
# https://github.com/django/django/blob/stable/1.3.x/django/core/validators.py#L45
|
||||
url_validation_regex = re.compile(
|
Loading…
Add table
Add a link
Reference in a new issue