Skip to content

Commit

Permalink
fixed tests that failed as a result of bumping to 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesstottmoj committed Apr 4, 2024
1 parent 4b31610 commit a3a6f5a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 57 deletions.
22 changes: 9 additions & 13 deletions tests/api/cluster/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def test_iam_role_name(users):
def test_create(helm, settings, users):
with patch("controlpanel.api.cluster.AWSRole.create_role") as aws_create_role:
user = users["normal_user"]
print(user)
cluster.User(user).create()
aws_create_role.assert_called_with(
user.iam_role_name,
Expand All @@ -27,18 +26,18 @@ def test_create(helm, settings, users):
call(
f"bootstrap-user-{user.slug}",
"mojanalytics/bootstrap-user",
f"--namespace=user-{user.slug}",
f"--set=Username={user.slug},",
f"Efsvolume={settings.EFS_VOLUME}",
f"--namespace=cpanel",
f"--set=Username={user.slug}",
),
call(
f"config-user-{user.slug}",
"mojanalytics/config-user",
f"provision-user-{user.slug}",
"mojanalytics/provision-user",
f"--namespace=user-{user.slug}",
f"--set=Username={user.slug}",
(f"--set=Username={user.slug},Efsvolume={settings.EFS_VOLUME},"
"OidcDomain=oidc.idp.example.com,Email=,Fullname="),
),
]
print(helm.upgrade_release.call_args_list)

helm.upgrade_release.assert_has_calls(expected_calls)


Expand All @@ -54,7 +53,7 @@ def test_reset_home(helm, users):
f"--set=Username={user.slug}",
),
]
print(helm.upgrade_release.call_args_list)

helm.upgrade_release.assert_has_calls(expected_calls)


Expand All @@ -71,17 +70,14 @@ def test_delete(aws_delete_role, helm, users):
Delete with Helm 3.
"""
user = users["normal_user"]
print(user)
helm.list_releases.return_value = [
"chart-release",
]
cluster.User(user).delete()
aws_delete_role.assert_called_with(user.iam_role_name)
expected_calls = [
call(f"user-{user.slug}", "chart-release"),
call("cpanel", "chart-release"),
call('user-bob', 'chart-release', dry_run=False),
]
print(helm.upgrade_release.call_args_list)
helm.delete.assert_has_calls(expected_calls)


Expand Down
28 changes: 0 additions & 28 deletions tests/api/models/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

# Third-party
import pytest
from django.conf import settings
from model_mommy import mommy

# First-party/Local
from controlpanel.api import cluster
Expand All @@ -22,32 +20,6 @@ def auth0():
yield auth0


def test_helm_create_user(helm):
user = mommy.prepare("api.User")

expected_calls = [
call(
f"bootstrap-user-{user.slug}",
"mojanalytics/bootstrap-user",
f"--set=Username={user.slug}",
),
call(
f"provision-user-{user.slug}",
"mojanalytics/provision-user",
f"--namespace=user-{user.slug}",
f"--set=Username={user.slug},",
f"Efsvolume={settings.EFS_VOLUME}",
),
call(
f"config-user-{user.slug}",
"mojanalytics/config-user",
f"--namespace=user-{user.slug}",
f"--set=Username={user.slug}",
),
]
helm.upgrade_release.assert_has_calls(expected_calls)


def test_helm_delete_user(helm, auth0):
user = User.objects.create(username="bob", auth0_id="github|user_2")
authz = auth0.ExtendedAuth0.return_value
Expand Down
26 changes: 16 additions & 10 deletions tests/frontend/views/test_app_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,22 @@ def fixture_delete_var():


@pytest.mark.parametrize(
"view,user,expected_status,data_input",
"view,user,expected_status,data_input,create_call_count,delete_call_count,expected_data",
[
(
create,
"superuser",
status.HTTP_302_FOUND,
dict(key="environment", value="prod", env_name="test_env"),
1,
0,
dict(env_name="test_env", key_name="XXX_environment", key_value="prod"),
),
(create, "owner", status.HTTP_200_OK, {}),
(create, "normal_user", status.HTTP_200_OK, {}),
(delete, "superuser", status.HTTP_302_FOUND, dict(key="hello")),
(delete, "owner", status.HTTP_302_FOUND, dict(key="hello")),
(delete, "normal_user", status.HTTP_403_FORBIDDEN, dict(key="hello")),
(create, "owner", status.HTTP_200_OK, {}, 0, 0, None),
(create, "normal_user", status.HTTP_200_OK, {}, 0, 0, None),
(delete, "superuser", status.HTTP_302_FOUND, dict(key="hello"), 0, 1, None),
(delete, "owner", status.HTTP_302_FOUND, dict(key="hello"), 0, 1, None),
(delete, "normal_user", status.HTTP_403_FORBIDDEN, dict(key="hello"), 0, 0, None),
],
)
def test_permission(
Expand All @@ -95,11 +98,14 @@ def test_permission(
data_input,
fixture_create_update_var,
fixture_delete_var,
create_call_count,
delete_call_count,
expected_data
):
client.force_login(users[user])
response = view(client, app, data_input)
assert response.status_code == expected_status
assert fixture_create_update_var.assert_called_once()
assert fixture_delete_var.assert_called_once()
if data_input:
assert fixture_create_update_var.called_once_with(data_input)
assert fixture_create_update_var.call_count == create_call_count
assert fixture_delete_var.call_count == delete_call_count
if data_input and create_call_count == 1:
fixture_create_update_var.assert_called_once_with(**expected_data)
13 changes: 7 additions & 6 deletions tests/frontend/views/test_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,19 @@ def test_add_secret_permissions(


@pytest.mark.parametrize( # noqa: F405
"user, key, data, expected_status",
[["superuser", "testing", {"env_name": "testing"}, 302],
["app_admin", "testing", {}, 302],
["normal_user", "testing", {}, 403]],
"user, key, data, expected_status, expected_calls",
[["superuser", "testing", {"env_name": "testing"}, 302, 1],
["app_admin", "testing", {}, 302, 1],
["normal_user", "testing", {}, 403, 0]],
)
def test_delete_secret(
client, app, users, fixture_delete_secret, user, key, data, expected_status
client, app, users, fixture_delete_secret, user, key, data, expected_status,
expected_calls
):
client.force_login(users[user])
response = delete_secret_post(client, app, key, data)
assert response.status_code == expected_status
assert fixture_delete_secret.assert_called_once()
assert fixture_delete_secret.call_count == expected_calls


def test_add_secret(fixture_create_update_secret,
Expand Down

0 comments on commit a3a6f5a

Please sign in to comment.