mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 13:35:23 +02:00
Added validators for users and recipes (#1052)
* Added validators for users and recipes provide a simple get api, allowing to test for existence of - user by username - recipe by slug - group by name (not tested yet) * updated formatting * Use group_id+slug for recipes, use ValidationRespone * Fixed Flake8 errors and warnings * add missing field for TestUser init
This commit is contained in:
parent
c8c02036a3
commit
e109391e9a
12 changed files with 129 additions and 2 deletions
1
tests/fixtures/fixture_admin.py
vendored
1
tests/fixtures/fixture_admin.py
vendored
|
@ -33,6 +33,7 @@ def admin_user(api_client: TestClient, api_routes: utils.AppRoutes):
|
|||
yield utils.TestUser(
|
||||
_group_id=user_data.get("groupId"),
|
||||
user_id=user_data.get("id"),
|
||||
username=user_data.get("username"),
|
||||
email=user_data.get("email"),
|
||||
token=token,
|
||||
)
|
||||
|
|
4
tests/fixtures/fixture_users.py
vendored
4
tests/fixtures/fixture_users.py
vendored
|
@ -28,6 +28,7 @@ def build_unique_user(group: str, api_client: requests) -> utils.TestUser:
|
|||
_group_id=user_data.get("groupId"),
|
||||
user_id=user_data.get("id"),
|
||||
email=user_data.get("email"),
|
||||
username=user_data.get("username"),
|
||||
token=token,
|
||||
)
|
||||
|
||||
|
@ -69,6 +70,7 @@ def g2_user(admin_token, api_client: TestClient, api_routes: utils.AppRoutes):
|
|||
_group_id=group_id,
|
||||
token=token,
|
||||
email=create_data["email"],
|
||||
username=create_data.get("username"),
|
||||
)
|
||||
finally:
|
||||
# TODO: Delete User after test
|
||||
|
@ -93,6 +95,7 @@ def unique_user(api_client: TestClient, api_routes: utils.AppRoutes):
|
|||
_group_id=user_data.get("groupId"),
|
||||
user_id=user_data.get("id"),
|
||||
email=user_data.get("email"),
|
||||
username=user_data.get("username"),
|
||||
token=token,
|
||||
)
|
||||
finally:
|
||||
|
@ -142,6 +145,7 @@ def user_tuple(admin_token, api_client: requests, api_routes: utils.AppRoutes) -
|
|||
utils.TestUser(
|
||||
_group_id=user_data.get("groupId"),
|
||||
user_id=user_data.get("id"),
|
||||
username=user_data.get("username"),
|
||||
email=user_data.get("email"),
|
||||
token=token,
|
||||
)
|
||||
|
|
46
tests/integration_tests/test_validators.py
Normal file
46
tests/integration_tests/test_validators.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
from fastapi.testclient import TestClient
|
||||
|
||||
from mealie.db.db_setup import create_session
|
||||
from mealie.schema.recipe.recipe import Recipe
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
class Routes:
|
||||
user = "/api/validators/user"
|
||||
recipe = "/api/validators/recipe"
|
||||
|
||||
|
||||
def test_validators_user(api_client: TestClient, unique_user: TestUser):
|
||||
session = create_session()
|
||||
|
||||
# Test existing user
|
||||
response = api_client.get(Routes.user + f"/{unique_user.username}")
|
||||
assert response.status_code == 200
|
||||
response_data = response.json()
|
||||
assert not response_data["valid"]
|
||||
|
||||
# Test non-existing user
|
||||
response = api_client.get(Routes.user + f"/{unique_user.username}2")
|
||||
assert response.status_code == 200
|
||||
response_data = response.json()
|
||||
assert response_data["valid"]
|
||||
|
||||
session.close()
|
||||
|
||||
|
||||
def test_validators_recipe(api_client: TestClient, random_recipe: Recipe):
|
||||
session = create_session()
|
||||
|
||||
# Test existing user
|
||||
response = api_client.get(Routes.recipe + f"/{random_recipe.group_id}/{random_recipe.slug}")
|
||||
assert response.status_code == 200
|
||||
response_data = response.json()
|
||||
assert not response_data["valid"]
|
||||
|
||||
# Test non-existing user
|
||||
response = api_client.get(Routes.recipe + f"/{random_recipe.group_id}/{random_recipe.slug}-test")
|
||||
assert response.status_code == 200
|
||||
response_data = response.json()
|
||||
assert response_data["valid"]
|
||||
|
||||
session.close()
|
|
@ -7,6 +7,7 @@ from uuid import UUID
|
|||
class TestUser:
|
||||
email: str
|
||||
user_id: UUID
|
||||
username: str
|
||||
_group_id: UUID
|
||||
token: Any
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue