From e21d7d941914d1aaa27e71b978241ddb165c1a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petra=20C=CC=8Ci=CC=81halova=CC=81?= Date: Thu, 12 Oct 2023 21:33:11 +0200 Subject: [PATCH] refactor: removed not used method _create_customer() --- tests/api/cross_access/test_view.py | 6 ++--- tests/identity_request.py | 22 ----------------- .../integration/test_integration_views.py | 20 ++++------------ tests/internal/test_views.py | 4 +--- tests/management/role/test_view.py | 2 +- tests/rbac/test_middleware.py | 24 ++++++++----------- 6 files changed, 20 insertions(+), 58 deletions(-) diff --git a/tests/api/cross_access/test_view.py b/tests/api/cross_access/test_view.py index d353e15e1..f79a98e00 100644 --- a/tests/api/cross_access/test_view.py +++ b/tests/api/cross_access/test_view.py @@ -47,7 +47,7 @@ def setUp(self): self.account = self.customer_data["account_id"] self.org_id = self.customer_data["org_id"] self.associate_non_admin_request_context = self._create_request_context( - self.customer_data, self.user_data, create_customer=False, is_org_admin=False, is_internal=True + self.customer_data, self.user_data, is_org_admin=False, is_internal=True ) self.associate_non_admin_request = self.associate_non_admin_request_context["request"] @@ -57,13 +57,13 @@ def setUp(self): self.not_anemic_customer_data["account_id"] = self.not_anemic_account self.not_anemic_customer_data["tenant_name"] = f"acct{self.not_anemic_account}" self.associate_not_anemic_request_context = self._create_request_context( - self.not_anemic_customer_data, self.user_data, create_customer=False, is_org_admin=False, is_internal=True + self.not_anemic_customer_data, self.user_data, is_org_admin=False, is_internal=True ) self.associate_not_anemic_request = self.associate_not_anemic_request_context["request"] self.not_anemic_headers = self.associate_not_anemic_request_context["request"].META self.associate_admin_request_context = self._create_request_context( - self.customer_data, self.user_data, create_customer=False, is_org_admin=True, is_internal=True + self.customer_data, self.user_data, is_org_admin=True, is_internal=True ) self.associate_admin_request = self.associate_admin_request_context["request"] diff --git a/tests/identity_request.py b/tests/identity_request.py index 5ed6e9065..451a8d0e7 100644 --- a/tests/identity_request.py +++ b/tests/identity_request.py @@ -70,31 +70,11 @@ def _create_user_data(cls): user_data = {"username": cls.fake.user_name(), "email": cls.fake.email()} return user_data - @classmethod - def _create_customer(cls, account, create_tenant=False, org_id=None): - """Create a customer. - - Args: - account (str): The account identifier - - Returns: - (Customer) The created customer - - """ - tenant_name = create_tenant_name(account) - tenant = None - if create_tenant: - tenant = Tenant(tenant_name=tenant_name, account_id=account, org_id=org_id) - tenant.save() - return tenant - @classmethod def _create_request_context( cls, customer_data, user_data, - create_customer=True, - create_tenant=False, is_org_admin=True, is_internal=False, cross_account=False, @@ -103,8 +83,6 @@ def _create_request_context( customer = customer_data account = customer.get("account_id") org_id = customer.get("org_id", None) - if create_customer: - cls.customer = cls._create_customer(account, create_tenant=create_tenant, org_id=org_id) identity = cls._build_identity(user_data, account, org_id, is_org_admin, is_internal) if cross_account: diff --git a/tests/internal/integration/test_integration_views.py b/tests/internal/integration/test_integration_views.py index b6ebd3e70..7cb2b39e7 100644 --- a/tests/internal/integration/test_integration_views.py +++ b/tests/internal/integration/test_integration_views.py @@ -36,9 +36,7 @@ def setUp(self): super().setUp() self.client = APIClient() self.customer = self.customer_data - self.internal_request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, is_internal=True, create_tenant=False - ) + self.internal_request_context = self._create_request_context(self.customer, self.user_data, is_internal=True) self.request = self.internal_request_context["request"] user = User() @@ -129,9 +127,7 @@ def test_groups_valid_account(self, mock_request): def test_groups_invalid_account(self): """Test that a /tenant//groups/?username= request from an external account fails.""" - external_request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, is_internal=False, create_tenant=False - ) + external_request_context = self._create_request_context(self.customer, self.user_data, is_internal=False) request = external_request_context["request"] response = self.client.get( f"/_private/api/v1/integrations/tenant/{self.tenant.org_id}/groups/?username=user_a", @@ -198,9 +194,7 @@ def test_groups_for_principal_valid_account(self): def test_groups_for_principal_invalid_account(self): """Test that a /tenant//principal/groups/ request from an external account fails.""" - external_request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, is_internal=False, create_tenant=False - ) + external_request_context = self._create_request_context(self.customer, self.user_data, is_internal=False) request = external_request_context["request"] response = self.client.get( f"/_private/api/v1/integrations/tenant/{self.tenant.org_id}/principal/user_a/groups/", @@ -274,9 +268,7 @@ def test_roles_from_group_invalid_uuid(self): def test_roles_from_group_invalid_account(self): """Test that a /tenant//groups//roles/ request from an external account fails.""" group_all_uuid = Group.objects.get(name="Group All").uuid - external_request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, is_internal=False, create_tenant=False - ) + external_request_context = self._create_request_context(self.customer, self.user_data, is_internal=False) request = external_request_context["request"] response = self.client.get( f"/_private/api/v1/integrations/tenant/{self.tenant.org_id}/groups/{group_all_uuid}/roles/", @@ -341,9 +333,7 @@ def test_roles_for_group_principal_valid(self): def test_roles_for_group_principal_invalid_account(self): """Test that a valid request to /tenant//principal/user_admin/groups//roles/ from an external account fails.""" group_all_uuid = Group.objects.get(name="Group All").uuid - external_request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, is_internal=False, create_tenant=False - ) + external_request_context = self._create_request_context(self.customer, self.user_data, is_internal=False) request = external_request_context["request"] response = self.client.get( f"/_private/api/v1/integrations/tenant/{self.tenant.org_id}/principal/user_admin/groups/{group_all_uuid}/roles/", diff --git a/tests/internal/test_views.py b/tests/internal/test_views.py index f3828b078..9afe68a60 100644 --- a/tests/internal/test_views.py +++ b/tests/internal/test_views.py @@ -44,9 +44,7 @@ def setUp(self): super().setUp() self.client = APIClient() self.customer = self.customer_data - self.internal_request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, is_internal=True, create_tenant=False - ) + self.internal_request_context = self._create_request_context(self.customer, self.user_data, is_internal=True) self.request = self.internal_request_context["request"] user = User() diff --git a/tests/management/role/test_view.py b/tests/management/role/test_view.py index 8f420000e..7440f34b6 100644 --- a/tests/management/role/test_view.py +++ b/tests/management/role/test_view.py @@ -968,7 +968,7 @@ def test_list_role_with_username_forbidden_to_nonadmin(self): """Test that non admin can not read a list of roles for username.""" # Setup non admin request non_admin_request_context = self._create_request_context( - self.customer_data, self.user_data, create_customer=False, is_org_admin=False + self.customer_data, self.user_data, is_org_admin=False ) non_admin_request = non_admin_request_context["request"] diff --git a/tests/rbac/test_middleware.py b/tests/rbac/test_middleware.py index 222012c40..d4c3755e2 100644 --- a/tests/rbac/test_middleware.py +++ b/tests/rbac/test_middleware.py @@ -96,7 +96,7 @@ def setUp(self): self.customer = self._create_customer_data() self.tenant_name = create_tenant_name(self.customer["account_id"]) self.org_id = self.customer["org_id"] - self.request_context = self._create_request_context(self.customer, self.user_data, create_customer=False) + self.request_context = self._create_request_context(self.customer, self.user_data) self.request = self.request_context["request"] self.request.path = "/api/v1/providers/" user = User() @@ -117,7 +117,7 @@ def test_get_tenant_with_user(self): def test_get_tenant_with_no_user(self): """Test that a 401 is returned.""" - request_context = self._create_request_context(self.customer, None, create_customer=False) + request_context = self._create_request_context(self.customer, None) mock_request = request_context["request"] mock_request.path = "/api/v1/providers/" middleware = IdentityHeaderMiddleware(get_response=IdentityHeaderMiddleware.process_request) @@ -129,7 +129,7 @@ def test_get_tenant_with_org_id(self): user_data = self._create_user_data() customer = self._create_customer_data() customer["org_id"] = "45321" - request_context = self._create_request_context(customer, user_data, create_customer=True) + request_context = self._create_request_context(customer, user_data) request = request_context["request"] request.path = "/api/v1/providers/" request.META["QUERY_STRING"] = "" @@ -154,7 +154,7 @@ def setUp(self): self.customer = self._create_customer_data() self.tenant_name = create_tenant_name(self.customer["account_id"]) self.org_id = self.customer["org_id"] - self.request_context = self._create_request_context(self.customer, self.user_data, create_customer=False) + self.request_context = self._create_request_context(self.customer, self.user_data) self.request = self.request_context["request"] self.request.path = "/api/v1/providers/" self.request.META["QUERY_STRING"] = "" @@ -171,7 +171,7 @@ def test_process_cross_account_request(self): middleware = IdentityHeaderMiddleware(get_response=IdentityHeaderMiddleware.process_request) # User without redhat email will fail. request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, cross_account=True, is_internal=True + self.customer, self.user_data, cross_account=True, is_internal=True ) mock_request = request_context["request"] mock_request.path = "/api/v1/providers/" @@ -181,9 +181,7 @@ def test_process_cross_account_request(self): # User with is_internal equal to False will fail. self.user_data["email"] = "test@redhat.com" - request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, cross_account=True - ) + request_context = self._create_request_context(self.customer, self.user_data, cross_account=True) mock_request = request_context["request"] mock_request.path = "/api/v1/providers/" @@ -193,7 +191,7 @@ def test_process_cross_account_request(self): # Success pass if user is internal and with redhat email self.user_data["email"] = "test@redhat.com" request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, cross_account=True, is_internal=True + self.customer, self.user_data, cross_account=True, is_internal=True ) mock_request = request_context["request"] mock_request.path = "/api/v1/providers/" @@ -227,7 +225,7 @@ def test_process_no_customer(self): customer = self._create_customer_data() account_id = customer["account_id"] del customer["account_id"] - request_context = self._create_request_context(customer, self.user_data, create_customer=False) + request_context = self._create_request_context(customer, self.user_data) mock_request = request_context["request"] mock_request.path = "/api/v1/providers/" middleware = IdentityHeaderMiddleware(get_response=IdentityHeaderMiddleware.process_request) @@ -260,7 +258,7 @@ def test_tenant_process_without_org_id(self): user_data = self._create_user_data() customer = self._create_customer_data() - request_context = self._create_request_context(customer, user_data, create_customer=False) + request_context = self._create_request_context(customer, user_data) request = request_context["request"] request.path = "/api/v1/providers/" request.META["QUERY_STRING"] = "" @@ -356,9 +354,7 @@ def setUp(self): super().setUp() self.user_data = self._create_user_data() self.customer = self._create_customer_data() - self.internal_request_context = self._create_request_context( - self.customer, self.user_data, create_customer=False, is_internal=True - ) + self.internal_request_context = self._create_request_context(self.customer, self.user_data, is_internal=True) def test_internal_user_can_access_private_api(self): request = self.internal_request_context["request"]