Skip to content

Commit

Permalink
Merge pull request RedHatInsights#941 from petracihalova/test-fix
Browse files Browse the repository at this point in the history
Fix for test_list_role_with_groups_in_fields_for_principal_scope_success()
  • Loading branch information
petracihalova authored Oct 17, 2023
2 parents da6ed2d + cc00bcc commit a2aeaa7
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions tests/management/role/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,15 +647,27 @@ def test_get_role_by_exact_display_name_no_match(self):
response = client.get(url, **self.headers)
self.assertEqual(response.data.get("meta").get("count"), 0)

@patch(
"management.principal.proxy.PrincipalProxy.request_filtered_principals",
return_value={"status_code": 200, "data": [{"username": "test_user"}]},
)
@patch("management.principal.proxy.PrincipalProxy.request_filtered_principals")
def test_list_role_with_groups_in_fields_for_principal_scope_success(self, mock_request):
"""
Test that we can read a list of roles and the groups_in fields is set correctly
for a principal scoped request.
"""
mock_request.return_value = {
"status_code": 200,
"data": [
{
"org_id": "100001",
"is_org_admin": True,
"is_internal": False,
"id": 52567473,
"username": self.principal.username,
"account_number": "1111111",
"is_active": True,
}
],
}

# create a role
role_name = "groupsInRole"
created_role = self.create_role("groupsInRole")
Expand All @@ -674,7 +686,7 @@ def test_list_role_with_groups_in_fields_for_principal_scope_success(self, mock_
self.assertEqual(created_policy.status_code, status.HTTP_201_CREATED)

# add user principal to the created group
principal_response = self.add_principal_to_group(group_uuid, self.user_data["username"])
principal_response = self.add_principal_to_group(group_uuid, self.principal.username)
self.assertEqual(principal_response.status_code, status.HTTP_200_OK, principal_response)

# hit /roles?groups_in, group should appear in groups_in
Expand All @@ -684,7 +696,7 @@ def test_list_role_with_groups_in_fields_for_principal_scope_success(self, mock_
new_display_fields.add(field_1)
new_display_fields.add(field_2)

url = "{}?add_fields={},{}&username=".format(URL, field_1, field_2, self.user_data["username"])
url = "{}?add_fields={},{}&username={}".format(URL, field_1, field_2, self.principal.username)
client = APIClient()
response = client.get(url, **self.headers)

Expand Down

0 comments on commit a2aeaa7

Please sign in to comment.