9ecef4c25f
This PR does too many things :( 1. Major refactoring of the dev/scripts and dev/code-generation folders. Primarily this was removing duplicate code and cleaning up some poorly written code snippets as well as making them more idempotent so then can be re-run over and over again but still maintain the same results. This is working on my machine, but I've been having problems in CI and comparing diffs so running generators in CI will have to wait. 2. Re-Implement using the generated api routes for testing This was a _huge_ refactor that touched damn near every test file but now we have auto-generated typed routes with inline hints and it's used for nearly every test excluding a few that use classes for better parameterization. This should greatly reduce errors when writing new tests. 3. Minor Perf improvements for the All Recipes endpoint A. Removed redundant loops B. Uses orjson to do the encoding directly and returns a byte response instead of relying on the default jsonable_encoder. 4. Fix some TS type errors that cropped up for seemingly no reason half way through the PR. See this issue https://github.com/phillipdupuis/pydantic-to-typescript/issues/28 Basically, the generated TS type is not-correct since Pydantic will automatically fill in null fields. The resulting TS type is generated with a ? to indicate it can be null even though we _know_ that i can't be.
77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
from dataclasses import dataclass
|
|
from uuid import UUID
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from mealie.repos.repository_factory import AllRepositories
|
|
from mealie.schema.recipe.recipe import Recipe
|
|
from tests.utils import api_routes, random_string
|
|
from tests.utils.fixture_schemas import TestUser
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class SimpleCase:
|
|
value: str
|
|
is_valid: bool
|
|
|
|
|
|
def test_validators_username(api_client: TestClient, unique_user: TestUser):
|
|
users = [
|
|
SimpleCase(value=unique_user.username, is_valid=False),
|
|
SimpleCase(value=random_string(), is_valid=True),
|
|
]
|
|
|
|
for user in users:
|
|
response = api_client.get(api_routes.validators_user_name + "?name=" + user.value)
|
|
assert response.status_code == 200
|
|
response_data = response.json()
|
|
assert response_data["valid"] == user.is_valid
|
|
|
|
|
|
def test_validators_email(api_client: TestClient, unique_user: TestUser):
|
|
emails = [
|
|
SimpleCase(value=unique_user.email, is_valid=False),
|
|
SimpleCase(value=f"{random_string()}@email.com", is_valid=True),
|
|
]
|
|
|
|
for user in emails:
|
|
response = api_client.get(api_routes.validators_user_email + "?email=" + user.value)
|
|
assert response.status_code == 200
|
|
response_data = response.json()
|
|
assert response_data["valid"] == user.is_valid
|
|
|
|
|
|
def test_validators_group_name(api_client: TestClient, unique_user: TestUser, database: AllRepositories):
|
|
group = database.groups.get_one(unique_user.group_id)
|
|
|
|
groups = [
|
|
SimpleCase(value=group.name, is_valid=False),
|
|
SimpleCase(value=random_string(), is_valid=True),
|
|
]
|
|
|
|
for user in groups:
|
|
response = api_client.get(api_routes.validators_group + "?name=" + user.value)
|
|
assert response.status_code == 200
|
|
response_data = response.json()
|
|
assert response_data["valid"] == user.is_valid
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class RecipeValidators:
|
|
name: str
|
|
group: UUID | str
|
|
is_valid: bool
|
|
|
|
|
|
def test_validators_recipe(api_client: TestClient, random_recipe: Recipe):
|
|
recipes = [
|
|
RecipeValidators(name=random_recipe.name, group=random_recipe.group_id, is_valid=False),
|
|
RecipeValidators(name=random_string(), group=random_recipe.group_id, is_valid=True),
|
|
RecipeValidators(name=random_string(), group=random_recipe.group_id, is_valid=True),
|
|
]
|
|
|
|
for recipe in recipes:
|
|
response = api_client.get(api_routes.validators_recipe + f"?group_id={recipe.group}&name={recipe.name}")
|
|
assert response.status_code == 200
|
|
response_data = response.json()
|
|
assert response_data["valid"] == recipe.is_valid
|