mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-06 05:55:23 +02:00
prs-fleshgolem-2070: feat: sqlalchemy 2.0 (#2096)
* upgrade sqlalchemy to 2.0 * rewrite all db models to sqla 2.0 mapping api * fix some importing and typing weirdness * fix types of a lot of nullable columns * remove get_ref methods * fix issues found by tests * rewrite all queries in repository_recipe to 2.0 style * rewrite all repository queries to 2.0 api * rewrite all remaining queries to 2.0 api * remove now-unneeded __allow_unmapped__ flag * remove and fix some unneeded cases of "# type: ignore" * fix formatting * bump black version * run black * can this please be the last one. okay. just. okay. * fix repository errors * remove return * drop open API validator --------- Co-authored-by: Sören Busch <fleshgolem@gmx.net>
This commit is contained in:
parent
91cd00976a
commit
9e77a9f367
86 changed files with 1776 additions and 1572 deletions
|
@ -30,7 +30,6 @@ def override_get_db():
|
|||
|
||||
@fixture(scope="session")
|
||||
def api_client():
|
||||
|
||||
app.dependency_overrides[generate_session] = override_get_db
|
||||
|
||||
yield TestClient(app)
|
||||
|
|
2
tests/fixtures/fixture_shopping_lists.py
vendored
2
tests/fixtures/fixture_shopping_lists.py
vendored
|
@ -25,7 +25,6 @@ def create_item(list_id: UUID4) -> dict:
|
|||
|
||||
@pytest.fixture(scope="function")
|
||||
def shopping_lists(database: AllRepositories, unique_user: TestUser):
|
||||
|
||||
models: list[ShoppingListOut] = []
|
||||
|
||||
for _ in range(3):
|
||||
|
@ -46,7 +45,6 @@ def shopping_lists(database: AllRepositories, unique_user: TestUser):
|
|||
|
||||
@pytest.fixture(scope="function")
|
||||
def shopping_list(database: AllRepositories, unique_user: TestUser):
|
||||
|
||||
model = database.group_shopping_lists.create(
|
||||
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id),
|
||||
)
|
||||
|
|
|
@ -60,7 +60,6 @@ def test_group_invitation_link(api_client: TestClient, unique_user: TestUser, in
|
|||
|
||||
|
||||
def test_group_invitation_delete_after_uses(api_client: TestClient, invite: str) -> None:
|
||||
|
||||
# Register First User
|
||||
_, r = register_user(api_client, invite)
|
||||
assert r.status_code == 201
|
||||
|
|
|
@ -85,7 +85,6 @@ def test_crud_mealplan(api_client: TestClient, unique_user: TestUser):
|
|||
|
||||
|
||||
def test_get_all_mealplans(api_client: TestClient, unique_user: TestUser):
|
||||
|
||||
for _ in range(3):
|
||||
new_plan = CreatePlanEntry(
|
||||
date=date.today(),
|
||||
|
|
|
@ -94,7 +94,6 @@ def test_shopping_list_items_get_one(
|
|||
unique_user: TestUser,
|
||||
list_with_items: ShoppingListOut,
|
||||
) -> None:
|
||||
|
||||
for _ in range(3):
|
||||
item = random.choice(list_with_items.list_items)
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ from tests.utils.fixture_schemas import TestUser
|
|||
def ten_slugs(
|
||||
api_client: TestClient, unique_user: TestUser, database: AllRepositories
|
||||
) -> Generator[list[str], None, None]:
|
||||
|
||||
slugs: list[str] = []
|
||||
|
||||
for _ in range(10):
|
||||
|
@ -98,7 +97,6 @@ def test_bulk_delete_recipes(
|
|||
database: AllRepositories,
|
||||
ten_slugs: list[str],
|
||||
):
|
||||
|
||||
payload = {"recipes": ten_slugs}
|
||||
|
||||
response = api_client.post(api_routes.recipes_bulk_actions_delete, json=payload, headers=unique_user.token)
|
||||
|
|
|
@ -13,7 +13,6 @@ from tests.utils.fixture_schemas import TestUser
|
|||
|
||||
@pytest.fixture(scope="function")
|
||||
def slug(api_client: TestClient, unique_user: TestUser, database: AllRepositories) -> Generator[str, None, None]:
|
||||
|
||||
payload = {"name": random_string(length=20)}
|
||||
response = api_client.post(api_routes.recipes, json=payload, headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
|
|
|
@ -25,13 +25,10 @@ def test_superuser_login(api_client: TestClient, admin_token):
|
|||
response = api_client.post(api_routes.auth_token, data=form_data)
|
||||
|
||||
assert response.status_code == 200
|
||||
new_token = json.loads(response.text).get("access_token")
|
||||
|
||||
response = api_client.get(api_routes.users_self, headers=admin_token)
|
||||
assert response.status_code == 200
|
||||
|
||||
return {"Authorization": f"Bearer {new_token}"}
|
||||
|
||||
|
||||
def test_user_token_refresh(api_client: TestClient, admin_user: TestUser):
|
||||
response = api_client.post(api_routes.auth_refresh, headers=admin_user.token)
|
||||
|
|
|
@ -113,7 +113,6 @@ def test_recipe_repo_get_by_categories_multi(database: AllRepositories, unique_u
|
|||
by_category = repo.get_by_categories(cast(list[RecipeCategory], created_categories))
|
||||
|
||||
assert len(by_category) == 10
|
||||
|
||||
for recipe_summary in by_category:
|
||||
for recipe_category in recipe_summary.recipe_category:
|
||||
assert recipe_category.id in known_category_ids
|
||||
|
|
|
@ -25,7 +25,6 @@ def test_camelize_variables():
|
|||
|
||||
|
||||
def test_cast_to():
|
||||
|
||||
model = TestModel(long_name="Hello", long_int=1, long_float=1.1)
|
||||
|
||||
model2 = model.cast(TestModel2, another_str="World")
|
||||
|
@ -37,7 +36,6 @@ def test_cast_to():
|
|||
|
||||
|
||||
def test_map_to():
|
||||
|
||||
model = TestModel(long_name="Model1", long_int=100, long_float=1.5)
|
||||
|
||||
model2 = TestModel2(long_name="Model2", long_int=1, long_float=1.1, another_str="World")
|
||||
|
|
|
@ -60,7 +60,6 @@ def test_get_scheduled_webhooks_filter_query(database: AllRepositories, unique_u
|
|||
assert result.enabled
|
||||
|
||||
for expected_item in expected:
|
||||
|
||||
if result.name == expected_item.name: # Names are uniquely generated so we can use this to compare
|
||||
assert result.enabled == expected_item.enabled
|
||||
break
|
||||
|
|
|
@ -256,7 +256,6 @@ ingredients_test_cases = (
|
|||
|
||||
@pytest.mark.parametrize("ingredients", ingredients_test_cases, ids=(x.test_id for x in ingredients_test_cases))
|
||||
def test_cleaner_clean_ingredients(ingredients: CleanerCase):
|
||||
|
||||
if ingredients.exception:
|
||||
with pytest.raises(ingredients.exception):
|
||||
cleaner.clean_ingredients(ingredients.input)
|
||||
|
|
|
@ -11,7 +11,6 @@ SUBJECTS = {"Mealie Forgot Password", "Invitation to join Mealie", "Test Email"}
|
|||
|
||||
class TestEmailSender(ABCEmailSender):
|
||||
def send(self, email_to: str, subject: str, html: str) -> bool:
|
||||
|
||||
# check email_to:
|
||||
assert email_to == FAKE_ADDRESS
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ class TestIngredient:
|
|||
|
||||
|
||||
def crf_exists() -> bool:
|
||||
|
||||
return shutil.which("crf_test") is not None
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
from openapi_spec_validator import openapi_v30_spec_validator, validate_spec
|
||||
|
||||
from mealie.app import app
|
||||
|
||||
|
||||
def test_validate_open_api_spec():
|
||||
open_api = app.openapi()
|
||||
validate_spec(open_api, validator=openapi_v30_spec_validator)
|
|
@ -9,9 +9,9 @@ from mealie.pkgs.stats.fs_stats import pretty_size
|
|||
(0, "0 bytes"),
|
||||
(1, "1 bytes"),
|
||||
(1024, "1.0 KB"),
|
||||
(1024 ** 2, "1.0 MB"),
|
||||
(1024 ** 2 * 1024, "1.0 GB"),
|
||||
(1024 ** 2 * 1024 * 1024, "1.0 TB"),
|
||||
(1024**2, "1.0 MB"),
|
||||
(1024**2 * 1024, "1.0 GB"),
|
||||
(1024**2 * 1024 * 1024, "1.0 TB"),
|
||||
],
|
||||
)
|
||||
def test_pretty_size(size: int, expected: str) -> None:
|
||||
|
|
|
@ -2,5 +2,4 @@ from fastapi.encoders import jsonable_encoder
|
|||
|
||||
|
||||
def jsonify(data):
|
||||
|
||||
return jsonable_encoder(data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue