1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-23 07:09:41 +02:00
* fix #1144

* fix type checks

* refactor test routes package

* fix #1208

* unify test routes into module
This commit is contained in:
Hayden 2022-05-07 20:08:04 -08:00 committed by GitHub
parent 07f6446526
commit 68f7efc177
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 189 additions and 148 deletions

View file

@ -27,7 +27,7 @@ def generate_create_data() -> dict:
def test_init_superuser(api_client: TestClient, admin_user: TestUser):
settings = get_app_settings()
response = api_client.get(routes.RoutesAdminUsers.item(admin_user.user_id), headers=admin_user.token)
response = api_client.get(routes.admin.AdminUsers.item(admin_user.user_id), headers=admin_user.token)
assert response.status_code == 200
admin_data = response.json()
@ -41,13 +41,13 @@ def test_init_superuser(api_client: TestClient, admin_user: TestUser):
def test_create_user(api_client: TestClient, api_routes: AppRoutes, admin_token):
create_data = generate_create_data()
response = api_client.post(routes.RoutesAdminUsers.base, json=create_data, headers=admin_token)
response = api_client.post(routes.admin.AdminUsers.base, json=create_data, headers=admin_token)
assert response.status_code == 201
form_data = {"username": create_data["email"], "password": create_data["password"]}
header = utils.login(form_data=form_data, api_client=api_client, api_routes=api_routes)
response = api_client.get(routes.RoutesUsers.self, headers=header)
response = api_client.get(routes.user.Users.self, headers=header)
assert response.status_code == 200
user_data = response.json()
@ -60,14 +60,14 @@ def test_create_user(api_client: TestClient, api_routes: AppRoutes, admin_token)
def test_create_user_as_non_admin(api_client: TestClient, user_token):
create_data = generate_create_data()
response = api_client.post(routes.RoutesAdminUsers.base, json=create_data, headers=user_token)
response = api_client.post(routes.admin.AdminUsers.base, json=create_data, headers=user_token)
assert response.status_code == 403
def test_update_user(api_client: TestClient, admin_user: TestUser):
# Create a new user
create_data = generate_create_data()
response = api_client.post(routes.RoutesAdminUsers.base, json=create_data, headers=admin_user.token)
response = api_client.post(routes.admin.AdminUsers.base, json=create_data, headers=admin_user.token)
assert response.status_code == 201
update_data = response.json()
@ -76,7 +76,7 @@ def test_update_user(api_client: TestClient, admin_user: TestUser):
update_data["email"] = random_email()
response = api_client.put(
routes.RoutesAdminUsers.item(update_data["id"]), headers=admin_user.token, json=update_data
routes.admin.AdminUsers.item(update_data["id"]), headers=admin_user.token, json=update_data
)
assert response.status_code == 200
@ -93,21 +93,21 @@ def test_update_other_user_as_not_admin(api_client: TestClient, unique_user: Tes
"admin": True,
}
response = api_client.put(
routes.RoutesAdminUsers.item(g2_user.user_id), headers=unique_user.token, json=update_data
routes.admin.AdminUsers.item(g2_user.user_id), headers=unique_user.token, json=update_data
)
assert response.status_code == 403
def test_self_demote_admin(api_client: TestClient, admin_user: TestUser):
response = api_client.get(routes.RoutesUsers.self, headers=admin_user.token)
response = api_client.get(routes.user.Users.self, headers=admin_user.token)
assert response.status_code == 200
user_data = response.json()
user_data["admin"] = False
response = api_client.put(
routes.RoutesAdminUsers.item(admin_user.user_id), headers=admin_user.token, json=user_data
routes.admin.AdminUsers.item(admin_user.user_id), headers=admin_user.token, json=user_data
)
assert response.status_code == 403
@ -122,12 +122,12 @@ def test_self_promote_admin(api_client: TestClient, unique_user: TestUser):
"admin": True,
}
response = api_client.put(
routes.RoutesAdminUsers.item(unique_user.user_id), headers=unique_user.token, json=update_data
routes.admin.AdminUsers.item(unique_user.user_id), headers=unique_user.token, json=update_data
)
assert response.status_code == 403
def test_delete_user(api_client: TestClient, admin_token, unique_user: TestUser):
response = api_client.delete(routes.RoutesAdminUsers.item(unique_user.user_id), headers=admin_token)
response = api_client.delete(routes.admin.AdminUsers.item(unique_user.user_id), headers=admin_token)
assert response.status_code == 200