Fix API tests after latest rework

This commit is contained in:
Florian Dupret 2021-04-27 20:59:25 +02:00
commit 57968e0492
4 changed files with 8 additions and 14 deletions

View file

@ -24,7 +24,7 @@ async def create_user(
new_user.password = get_password_hash(new_user.password) 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]) @router.get("", response_model=list[UserOut])

View file

@ -13,12 +13,7 @@ def group_data():
def test_create_group(api_client: TestClient, api_routes: AppRoutes, token): def test_create_group(api_client: TestClient, api_routes: AppRoutes, token):
response = api_client.post(api_routes.groups, json={"name": "Test Group"}, headers=token) response = api_client.post(api_routes.groups, json={"name": "Test Group"}, headers=token)
assert response.status_code == 200 assert response.status_code == 201
assert json.loads(response.content) == {
"snackbar": {"text": "User Group Created", "type": "success"},
"created": True,
}
def test_get_self_group(api_client: TestClient, api_routes: AppRoutes, token): def test_get_self_group(api_client: TestClient, api_routes: AppRoutes, token):
@ -42,7 +37,6 @@ def test_update_group(api_client: TestClient, api_routes: AppRoutes, token):
# Test Update # Test Update
response = api_client.put(api_routes.groups_id(2), json=new_data, headers=token) response = api_client.put(api_routes.groups_id(2), json=new_data, headers=token)
assert response.status_code == 200 assert response.status_code == 200
assert json.loads(response.text) == {"snackbar": {"text": "Group Settings Updated", "type": "success"}}
# Validate Changes # Validate Changes
response = api_client.get(api_routes.groups, headers=token) response = api_client.get(api_routes.groups, headers=token)
@ -51,13 +45,13 @@ def test_update_group(api_client: TestClient, api_routes: AppRoutes, token):
assert next(id_2) == new_data 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) 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): def test_delete_group(api_client: TestClient, api_routes: AppRoutes, token):
response = api_client.delete(api_routes.groups_id(2), headers=token) response = api_client.delete(api_routes.groups_id(2), headers=token)
assert json.loads(response.text) is None assert response.status_code == 200

View file

@ -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) meal_plan = get_meal_plan_template(slug_1, slug_2)
response = api_client.post(api_routes.meal_plans_create, json=meal_plan, headers=token) 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): def test_read_mealplan(api_client: TestClient, api_routes: AppRoutes, slug_1, slug_2, token):

View file

@ -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): 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) 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) response = api_client.get(api_routes.themes_theme_name(new_theme.get("name")), headers=token)
assert response.status_code == 200 assert response.status_code == 200