2022-05-01 12:45:50 -08:00
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
2024-08-22 10:14:32 -05:00
|
|
|
from mealie.schema.response.pagination import PaginationQuery
|
2022-10-18 14:49:41 -08:00
|
|
|
from tests.utils import api_routes
|
2022-05-01 12:45:50 -08:00
|
|
|
from tests.utils.fixture_schemas import TestUser
|
|
|
|
|
|
|
|
|
|
|
|
def test_seed_invalid_locale(api_client: TestClient, unique_user: TestUser):
|
2022-10-18 14:49:41 -08:00
|
|
|
for route in (api_routes.groups_seeders_foods, api_routes.groups_seeders_labels, api_routes.groups_seeders_units):
|
2022-05-01 12:45:50 -08:00
|
|
|
resp = api_client.post(route, json={"locale": "invalid"}, headers=unique_user.token)
|
|
|
|
assert resp.status_code == 422
|
|
|
|
|
|
|
|
|
2024-08-22 10:14:32 -05:00
|
|
|
def test_seed_foods(api_client: TestClient, unique_user: TestUser):
|
2025-01-31 21:17:43 -05:00
|
|
|
CREATED_FOODS = 2687
|
2024-08-22 10:14:32 -05:00
|
|
|
database = unique_user.repos
|
2022-05-01 12:45:50 -08:00
|
|
|
|
|
|
|
# Check that the foods was created
|
2024-08-22 10:14:32 -05:00
|
|
|
foods = database.ingredient_foods.page_all(PaginationQuery(page=1, per_page=-1)).items
|
2022-05-01 12:45:50 -08:00
|
|
|
assert len(foods) == 0
|
|
|
|
|
2022-10-18 14:49:41 -08:00
|
|
|
resp = api_client.post(api_routes.groups_seeders_foods, json={"locale": "en-US"}, headers=unique_user.token)
|
2022-05-01 12:45:50 -08:00
|
|
|
assert resp.status_code == 200
|
|
|
|
|
|
|
|
# Check that the foods was created
|
2024-08-22 10:14:32 -05:00
|
|
|
foods = database.ingredient_foods.page_all(PaginationQuery(page=1, per_page=-1)).items
|
2022-05-01 12:45:50 -08:00
|
|
|
assert len(foods) == CREATED_FOODS
|
|
|
|
|
|
|
|
|
2024-08-22 10:14:32 -05:00
|
|
|
def test_seed_units(api_client: TestClient, unique_user: TestUser):
|
2024-08-20 10:33:20 -04:00
|
|
|
CREATED_UNITS = 23
|
2024-08-22 10:14:32 -05:00
|
|
|
database = unique_user.repos
|
2022-05-01 12:45:50 -08:00
|
|
|
|
|
|
|
# Check that the foods was created
|
2024-08-22 10:14:32 -05:00
|
|
|
units = database.ingredient_units.page_all(PaginationQuery(page=1, per_page=-1)).items
|
2022-05-01 12:45:50 -08:00
|
|
|
assert len(units) == 0
|
|
|
|
|
2022-10-18 14:49:41 -08:00
|
|
|
resp = api_client.post(api_routes.groups_seeders_units, json={"locale": "en-US"}, headers=unique_user.token)
|
2022-05-01 12:45:50 -08:00
|
|
|
assert resp.status_code == 200
|
|
|
|
|
|
|
|
# Check that the foods was created
|
2024-08-22 10:14:32 -05:00
|
|
|
units = database.ingredient_units.page_all(PaginationQuery(page=1, per_page=-1)).items
|
2022-05-01 12:45:50 -08:00
|
|
|
assert len(units) == CREATED_UNITS
|
|
|
|
|
|
|
|
|
2024-08-22 10:14:32 -05:00
|
|
|
def test_seed_labels(api_client: TestClient, unique_user: TestUser):
|
2025-01-31 21:17:43 -05:00
|
|
|
CREATED_LABELS = 32
|
2024-08-22 10:14:32 -05:00
|
|
|
database = unique_user.repos
|
2022-05-01 12:45:50 -08:00
|
|
|
|
|
|
|
# Check that the foods was created
|
2024-08-22 10:14:32 -05:00
|
|
|
labels = database.group_multi_purpose_labels.page_all(PaginationQuery(page=1, per_page=-1)).items
|
2022-05-01 12:45:50 -08:00
|
|
|
assert len(labels) == 0
|
|
|
|
|
2022-10-18 14:49:41 -08:00
|
|
|
resp = api_client.post(api_routes.groups_seeders_labels, json={"locale": "en-US"}, headers=unique_user.token)
|
2022-05-01 12:45:50 -08:00
|
|
|
assert resp.status_code == 200
|
|
|
|
|
|
|
|
# Check that the foods was created
|
2024-08-22 10:14:32 -05:00
|
|
|
labels = database.group_multi_purpose_labels.page_all(PaginationQuery(page=1, per_page=-1)).items
|
2022-05-01 12:45:50 -08:00
|
|
|
assert len(labels) == CREATED_LABELS
|