diff --git a/tests/api/cluster/test_user.py b/tests/api/cluster/test_user.py index f59321c33..6abed4c02 100644 --- a/tests/api/cluster/test_user.py +++ b/tests/api/cluster/test_user.py @@ -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, @@ -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) @@ -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) @@ -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) diff --git a/tests/api/models/test_user.py b/tests/api/models/test_user.py index c1dd9497e..2a629fe5f 100644 --- a/tests/api/models/test_user.py +++ b/tests/api/models/test_user.py @@ -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 @@ -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 diff --git a/tests/frontend/views/test_app_variables.py b/tests/frontend/views/test_app_variables.py index d82085039..1e5f5fd96 100644 --- a/tests/frontend/views/test_app_variables.py +++ b/tests/frontend/views/test_app_variables.py @@ -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( @@ -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) diff --git a/tests/frontend/views/test_secrets.py b/tests/frontend/views/test_secrets.py index 0acb94beb..4d36f7233 100644 --- a/tests/frontend/views/test_secrets.py +++ b/tests/frontend/views/test_secrets.py @@ -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,