From 57968e04920c37b250eaa0aecd7bebf1dde63184 Mon Sep 17 00:00:00 2001 From: Florian Dupret <34862846+sephrat@users.noreply.github.com> Date: Tue, 27 Apr 2021 20:59:25 +0200 Subject: [PATCH] Fix API tests after latest rework --- mealie/routes/users/crud.py | 2 +- tests/integration_tests/test_group_routes.py | 16 +++++----------- tests/integration_tests/test_meal_routes.py | 2 +- tests/integration_tests/test_settings_routes.py | 2 +- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/mealie/routes/users/crud.py b/mealie/routes/users/crud.py index 655972783..d11d6a852 100644 --- a/mealie/routes/users/crud.py +++ b/mealie/routes/users/crud.py @@ -24,7 +24,7 @@ async def create_user( new_user.password = get_password_hash(new_user.password) - data = db.users.create(session, new_user.dict()) + return db.users.create(session, new_user.dict()) @router.get("", response_model=list[UserOut]) diff --git a/tests/integration_tests/test_group_routes.py b/tests/integration_tests/test_group_routes.py index c38235e72..d06f20027 100644 --- a/tests/integration_tests/test_group_routes.py +++ b/tests/integration_tests/test_group_routes.py @@ -13,12 +13,7 @@ def group_data(): def test_create_group(api_client: TestClient, api_routes: AppRoutes, token): response = api_client.post(api_routes.groups, json={"name": "Test Group"}, headers=token) - assert response.status_code == 200 - - assert json.loads(response.content) == { - "snackbar": {"text": "User Group Created", "type": "success"}, - "created": True, - } + assert response.status_code == 201 def test_get_self_group(api_client: TestClient, api_routes: AppRoutes, token): @@ -42,8 +37,7 @@ def test_update_group(api_client: TestClient, api_routes: AppRoutes, token): # Test Update response = api_client.put(api_routes.groups_id(2), json=new_data, headers=token) assert response.status_code == 200 - assert json.loads(response.text) == {"snackbar": {"text": "Group Settings Updated", "type": "success"}} - + # Validate Changes response = api_client.get(api_routes.groups, headers=token) all_groups = json.loads(response.text) @@ -51,13 +45,13 @@ def test_update_group(api_client: TestClient, api_routes: AppRoutes, token): assert next(id_2) == new_data -def test_block_delete(api_client: TestClient, api_routes: AppRoutes, token): +def test_home_group_not_deletable(api_client: TestClient, api_routes: AppRoutes, token): response = api_client.delete(api_routes.groups_id(1), headers=token) - assert json.loads(response.text) == {"snackbar": {"text": "Cannot delete default group", "type": "error"}} + assert response.status_code == 400 def test_delete_group(api_client: TestClient, api_routes: AppRoutes, token): response = api_client.delete(api_routes.groups_id(2), headers=token) - assert json.loads(response.text) is None + assert response.status_code == 200 diff --git a/tests/integration_tests/test_meal_routes.py b/tests/integration_tests/test_meal_routes.py index 760a05a40..3ef8537cd 100644 --- a/tests/integration_tests/test_meal_routes.py +++ b/tests/integration_tests/test_meal_routes.py @@ -50,7 +50,7 @@ def test_create_mealplan(api_client: TestClient, api_routes: AppRoutes, slug_1, meal_plan = get_meal_plan_template(slug_1, slug_2) response = api_client.post(api_routes.meal_plans_create, json=meal_plan, headers=token) - assert response.status_code == 200 + assert response.status_code == 201 def test_read_mealplan(api_client: TestClient, api_routes: AppRoutes, slug_1, slug_2, token): diff --git a/tests/integration_tests/test_settings_routes.py b/tests/integration_tests/test_settings_routes.py index de613c1c9..2a6f30510 100644 --- a/tests/integration_tests/test_settings_routes.py +++ b/tests/integration_tests/test_settings_routes.py @@ -62,7 +62,7 @@ def test_default_theme(api_client: TestClient, api_routes: AppRoutes, default_th def test_create_theme(api_client: TestClient, api_routes: AppRoutes, new_theme, token): response = api_client.post(api_routes.themes_create, json=new_theme, headers=token) - assert response.status_code == 200 + assert response.status_code == 201 response = api_client.get(api_routes.themes_theme_name(new_theme.get("name")), headers=token) assert response.status_code == 200