forked from RedHatInsights/insights-rbac
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RedHatInsights#940 from petracihalova/remove-unnec…
…essary-testdata Remove unnecessary testdata
- Loading branch information
Showing
1 changed file
with
14 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": "[email protected]"} | ||
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) | ||
|
@@ -831,34 +783,33 @@ 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": [ | ||
{ | ||
"org_id": "100001", | ||
"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) | ||
|
||
|