From 826bdbc6a62001193115e34fa88bb182ad6ad268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petra=20C=CC=8Ci=CC=81halova=CC=81?= Date: Sat, 14 Oct 2023 15:30:56 +0200 Subject: [PATCH 1/2] test 'test_list_role_with_additional_fields_username_success' updated to use the default test data --- tests/management/role/test_view.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/management/role/test_view.py b/tests/management/role/test_view.py index 156804e1..f6072028 100644 --- a/tests/management/role/test_view.py +++ b/tests/management/role/test_view.py @@ -831,9 +831,16 @@ def test_list_role_fail_with_invalid_username(self, mock_request): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) - @patch( - "management.principal.proxy.PrincipalProxy.request_filtered_principals", - return_value={ + @patch("management.principal.proxy.PrincipalProxy.request_filtered_principals") + def test_list_role_with_additional_fields_username_success(self, mock_request): + """Test that we can read a list of roles and add fields for username.""" + field_1 = "groups_in_count" + field_2 = "groups_in" + new_display_fields = self.display_fields + new_display_fields.add(field_1) + new_display_fields.add(field_2) + + mock_request.return_value = { "status_code": 200, "data": [ { @@ -841,24 +848,16 @@ def test_list_role_fail_with_invalid_username(self, mock_request): "is_org_admin": True, "is_internal": False, "id": 52567473, - "username": "test_user", + "username": self.principal.username, "account_number": "1111111", "is_active": True, } ], - }, - ) - def test_list_role_with_additional_fields_username_success(self, mock_request): - """Test that we can read a list of roles and add fields for username.""" - field_1 = "groups_in_count" - field_2 = "groups_in" - new_display_fields = self.display_fields - new_display_fields.add(field_1) - new_display_fields.add(field_2) + } - url = "{}?add_fields={},{}&username={}".format(URL, field_1, field_2, self.test_principal.username) + url = "{}?add_fields={},{}&username={}".format(URL, field_1, field_2, self.principal.username) client = APIClient() - response = client.get(url, **self.test_headers) + response = client.get(url, **self.headers) self.assertEqual(len(response.data.get("data")), 4) From 7e523d15cf66c7650f936d7f9c22b9ce8551251a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petra=20C=CC=8Ci=CC=81halova=CC=81?= Date: Sat, 14 Oct 2023 15:31:34 +0200 Subject: [PATCH 2/2] removed not used test data in the class 'RoleViewsetTests' --- tests/management/role/test_view.py | 48 ------------------------------ 1 file changed, 48 deletions(-) diff --git a/tests/management/role/test_view.py b/tests/management/role/test_view.py index f6072028..1e2d5763 100644 --- a/tests/management/role/test_view.py +++ b/tests/management/role/test_view.py @@ -23,7 +23,6 @@ from rest_framework import status from rest_framework.test import APIClient -from api.models import Tenant from management.cache import TenantCache from management.models import ( Group, @@ -87,53 +86,6 @@ def setUp(self): "external_tenant", } - self.test_tenant = Tenant(tenant_name="acct1111111", account_id="1111111", org_id="100001", ready=True) - self.test_tenant.save() - self.test_principal = Principal(username="test_user", tenant=self.test_tenant) - self.test_principal.save() - - user_data = {"username": "test_user", "email": "test@gmail.com"} - request_context = self._create_request_context( - {"account_id": "1111111", "tenant_name": "acct1111111", "org_id": "100001"}, user_data, is_org_admin=True - ) - request = request_context["request"] - self.test_headers = request.META - - self.test_policy = Policy.objects.create(name="policyA", tenant=self.test_tenant) - self.test_group = Group(name="groupA", description="groupA description", tenant=self.test_tenant) - self.test_group.save() - self.test_group.principals.add(self.test_principal) - self.test_group.policies.add(self.test_policy) - self.test_group.save() - - self.test_policy_two = Policy.objects.create(name="policyB", tenant=self.test_tenant) - self.test_group_two = Group(name="groupB", description="groupB description", tenant=self.test_tenant) - self.test_group_two.save() - self.test_group_two.principals.add(self.test_principal) - self.test_group_two.policies.add(self.test_policy_two) - self.test_group_two.save() - - self.test_adminRole = Role(**admin_def_role_config, tenant=self.test_tenant) - self.test_adminRole.save() - - self.test_platformAdminRole = Role(**platform_admin_def_role_config, tenant=self.test_tenant) - self.test_platformAdminRole.save() - - self.test_sysRole = Role(**sys_role_config, tenant=self.test_tenant) - self.test_sysRole.save() - - self.test_defRole = Role(**def_role_config, tenant=self.test_tenant) - self.test_defRole.save() - self.test_defRole.save() - - self.test_policy.roles.add( - self.test_defRole, self.test_sysRole, self.test_adminRole, self.test_platformAdminRole - ) - self.test_policy.save() - - self.test_policy_two.roles.add(self.test_platformAdminRole) - self.test_policy_two.save() - self.principal = Principal(username=self.user_data["username"], tenant=self.tenant) self.principal.save() self.policy = Policy.objects.create(name="policyA", tenant=self.tenant)