Skip to content

Commit

Permalink
rename service account 'clientID' into 'clientId' in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petracihalova committed Aug 5, 2024
1 parent 33ecf7e commit 79c4b79
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
36 changes: 18 additions & 18 deletions tests/management/group/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def test_read_group_list_success(self):
"management.principal.it_service.ITService.request_service_accounts",
return_value=[
{
"clientID": "b7a82f30-bcef-013c-2452-6aa2427b506c",
"clientId": "b7a82f30-bcef-013c-2452-6aa2427b506c",
"name": f"service_account_name",
"description": f"Service Account description",
"owner": "jsmith",
Expand Down Expand Up @@ -2105,7 +2105,7 @@ def test_get_group_service_account_success(self, mock_request):
for uuid in self.sa_client_ids:
mocked_values.append(
{
"clientID": uuid,
"clientId": uuid,
"name": f"service_account_name_{uuid.split('-')[0]}",
"description": f"Service Account description {uuid.split('-')[0]}",
"owner": "jsmith",
Expand All @@ -2129,11 +2129,11 @@ def test_get_group_service_account_success(self, mock_request):
sa = response.data.get("data")[0]
self.assertCountEqual(
list(sa.keys()),
["clientID", "name", "description", "owner", "time_created", "type", "username"],
["clientId", "name", "description", "owner", "time_created", "type", "username"],
)

for mock_sa in mocked_values:
if mock_sa["clientID"] == sa.get("clientID"):
if mock_sa["clientId"] == sa.get("clientId"):
self.assertEqual(sa.get("name"), mock_sa["name"])
self.assertEqual(sa.get("description"), mock_sa["description"])
self.assertEqual(sa.get("owner"), mock_sa["owner"])
Expand All @@ -2147,7 +2147,7 @@ def test_get_group_service_account_empty_response(self, mock_request):
uuid = self.sa_client_ids[0]
mock_request.return_value = [
{
"clientID": uuid,
"clientId": uuid,
"name": f"service_account_name_{uuid.split('-')[0]}",
"description": f"Service Account description {uuid.split('-')[0]}",
"owner": "jsmith",
Expand All @@ -2174,7 +2174,7 @@ def test_get_group_service_account_valid_limit_offset(self, mock_request):
for uuid in self.sa_client_ids:
mocked_values.append(
{
"clientID": uuid,
"clientId": uuid,
"name": f"service_account_name_{uuid.split('-')[0]}",
"description": f"Service Account description {uuid.split('-')[0]}",
"owner": "jsmith",
Expand Down Expand Up @@ -2220,7 +2220,7 @@ def test_get_group_service_account_invalid_limit_offset(self, mock_request):
for uuid in self.sa_client_ids:
mocked_values.append(
{
"clientID": uuid,
"clientId": uuid,
"name": f"service_account_name_{uuid.split('-')[0]}",
"description": f"Service Account description {uuid.split('-')[0]}",
"owner": "jsmith",
Expand Down Expand Up @@ -2577,7 +2577,7 @@ def test_get_group_service_account_filter_by_username_success(self, mock_request
for uuid in [uuid1, uuid2]:
mocked_values.append(
{
"clientID": uuid,
"clientId": uuid,
"name": f"service_account_name_{uuid.split('-')[0]}",
"description": f"Service Account description {uuid.split('-')[0]}",
"owner": "jsmith",
Expand Down Expand Up @@ -2615,7 +2615,7 @@ def test_get_group_service_account_filter_by_username_success(self, mock_request
self.assertEqual(len(response.data.get("data")), 1)

sa = response.data.get("data")[0]
self.assertEqual(sa.get("clientID"), uuid2)
self.assertEqual(sa.get("clientId"), uuid2)
self.assertEqual(sa.get("username"), "service-account-" + uuid2)

# Test that 0 SA is returned for SA with "r" in username
Expand Down Expand Up @@ -2890,7 +2890,7 @@ def test_group_service_account_with_user_administrator_role_add_principals(
# Create the test data to add a service account and a regular user to the group.
test_data = {
"principals": [
{"clientID": new_sa_principal.service_account_id, "type": "service-account"},
{"clientId": new_sa_principal.service_account_id, "type": "service-account"},
{"username": new_principal.username},
]
}
Expand Down Expand Up @@ -3184,7 +3184,7 @@ def test_group_user_with_user_administrator_role_add_principals(self, request_fi
# Create the test data to add a service account and a regular user to the group.
test_data = {
"principals": [
{"clientID": new_sa_principal.service_account_id, "type": "service-account"},
{"clientId": new_sa_principal.service_account_id, "type": "service-account"},
{"username": new_principal.username},
]
}
Expand Down Expand Up @@ -3718,7 +3718,7 @@ def test_list_service_account_principals_in_group_with_User_Access_Admin_success
sa_uuid = sa_principal.service_account_id
mocked_values = [
{
"clientID": sa_uuid,
"clientId": sa_uuid,
"name": f"Service Account name",
"description": f"Service Account description",
"owner": "jsmith",
Expand Down Expand Up @@ -3798,7 +3798,7 @@ def test_add_service_account_principal_in_group_without_User_Access_Admin_fail(s
sa_uuid = sa_principal.service_account_id
mocked_values = [
{
"clientID": sa_uuid,
"clientId": sa_uuid,
"name": f"Service Account name",
"description": f"Service Account description",
"owner": "jsmith",
Expand All @@ -3812,7 +3812,7 @@ def test_add_service_account_principal_in_group_without_User_Access_Admin_fail(s
url = reverse("group-principals", kwargs={"uuid": test_group.uuid})
client = APIClient()

request_body = {"principals": [{"clientID": sa_uuid, "type": "service-account"}]}
request_body = {"principals": [{"clientId": sa_uuid, "type": "service-account"}]}

response = client.post(url, request_body, format="json", **self.headers_user_based_principal)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Expand Down Expand Up @@ -3888,7 +3888,7 @@ def test_add_service_account_principal_in_group_with_User_Access_Admin_success(s
sa_uuid = sa_principal.service_account_id
mocked_values = [
{
"clientID": sa_uuid,
"clientId": sa_uuid,
"name": f"Service Account name",
"description": f"Service Account description",
"owner": "jsmith",
Expand All @@ -3902,7 +3902,7 @@ def test_add_service_account_principal_in_group_with_User_Access_Admin_success(s
url = reverse("group-principals", kwargs={"uuid": test_group.uuid})
client = APIClient()

request_body = {"principals": [{"clientID": sa_uuid, "type": "service-account"}]}
request_body = {"principals": [{"clientId": sa_uuid, "type": "service-account"}]}

response = client.post(url, request_body, format="json", **self.headers_user_based_principal)
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down Expand Up @@ -3995,7 +3995,7 @@ def test_add_service_account_principal_in_group_with_User_Access_Admin_fail(self
sa_uuid = sa_principal.service_account_id
mocked_values = [
{
"clientID": sa_uuid,
"clientId": sa_uuid,
"name": f"Service Account name",
"description": f"Service Account description",
"owner": "jsmith",
Expand All @@ -4009,7 +4009,7 @@ def test_add_service_account_principal_in_group_with_User_Access_Admin_fail(self
url = reverse("group-principals", kwargs={"uuid": test_group.uuid})
client = APIClient()

request_body = {"principals": [{"clientID": sa_uuid, "type": "service-account"}]}
request_body = {"principals": [{"clientId": sa_uuid, "type": "service-account"}]}

response = client.post(url, request_body, format="json", **self.headers_user_based_principal)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Expand Down
42 changes: 21 additions & 21 deletions tests/management/principal/test_it_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _assert_created_sa_and_result_are_same(
# Make it easier to find the service accounts by their client ID.
result_sas_by_client_id: dict[str[dict, str]] = {}
for sa in function_result:
result_sas_by_client_id[sa["clientID"]] = sa
result_sas_by_client_id[sa["clientId"]] = sa

# Assert that the only service accounts in the result are the ones from the tenant associated to the user
# that was passed to the function under test.
Expand All @@ -180,7 +180,7 @@ def _assert_created_sa_and_result_are_same(

self.assertEqual(
sa_principal.service_account_id,
sa["clientID"],
sa["clientId"],
"the mocked service account's client ID should be the service account principal's ID",
)

Expand Down Expand Up @@ -221,9 +221,9 @@ def _assert_IT_to_RBAC_model_transformations(
# Rearrange RBAC's service accounts by client ID for an easier search later on.
rbac_service_accounts_by_cid: dict[str, dict[str, str]] = {}
for rbac_sa in rbac_service_accounts:
rbac_sa_cid = rbac_sa.get("clientID")
rbac_sa_cid = rbac_sa.get("clientId")
if not rbac_sa_cid:
self.fail(f'the transformed service account does not have the "clientID" property: {rbac_sa}')
self.fail(f'the transformed service account does not have the "clientId" property: {rbac_sa}')

rbac_service_accounts_by_cid[rbac_sa_cid] = rbac_sa

Expand All @@ -241,9 +241,9 @@ def _assert_IT_to_RBAC_model_transformations(
)

# Assert that the client IDs are the same.
rbac_sa_client_id = rbac_sa.get("clientID")
rbac_sa_client_id = rbac_sa.get("clientId")
if not rbac_sa_client_id:
self.fail(f'the transformed RBAC service account does not contain the "clientID" property: {rbac_sa}')
self.fail(f'the transformed RBAC service account does not contain the "clientId" property: {rbac_sa}')

self.assertEqual(rbac_sa_client_id, client_id, "the client IDs for the RBAC and IT models do not match")

Expand Down Expand Up @@ -593,7 +593,7 @@ def test_is_service_account_valid(self, request_service_accounts: mock.Mock):
user.bearer_token = "mocked-bt"

expected_client_id = str(uuid.uuid4())
request_service_accounts.return_value = [{"clientID": expected_client_id}]
request_service_accounts.return_value = [{"clientId": expected_client_id}]

self.assertEqual(
True,
Expand All @@ -602,9 +602,9 @@ def test_is_service_account_valid(self, request_service_accounts: mock.Mock):
)

request_service_accounts.return_value = [
{"clientID": str(uuid.uuid4())},
{"clientID": str(uuid.uuid4())},
{"clientID": expected_client_id},
{"clientId": str(uuid.uuid4())},
{"clientId": str(uuid.uuid4())},
{"clientId": expected_client_id},
]

self.assertEqual(
Expand All @@ -629,9 +629,9 @@ def test_is_service_account_invalid(self, request_service_accounts: mock.Mock):
)

request_service_accounts.return_value = [
{"clientID": str(uuid.uuid4())},
{"clientID": str(uuid.uuid4())},
{"clientID": str(uuid.uuid4())},
{"clientId": str(uuid.uuid4())},
{"clientId": str(uuid.uuid4())},
{"clientId": str(uuid.uuid4())},
]

self.assertEqual(
Expand All @@ -657,7 +657,7 @@ def test_is_service_account_valid_zero_results_from_it(self, request_service_acc
def test_is_service_account_valid_one_matching_result_from_it(self, request_service_accounts: mock.Mock):
"""Test that the function under test positively validates the given service account if IT responds with that service account."""
client_id = "client-id-123"
request_service_accounts.return_value = [{"clientID": client_id}]
request_service_accounts.return_value = [{"clientId": client_id}]
user = User()
user.bearer_token = "mocked-bt"

Expand All @@ -671,7 +671,7 @@ def test_is_service_account_valid_one_matching_result_from_it(self, request_serv
def test_is_service_account_valid_not_matching_result_from_it(self, request_service_accounts: mock.Mock):
"""Test that the function under test does not validate the given service account if IT does not return a response with a proper service account."""
client_id = "client-id-123"
request_service_accounts.return_value = [{"clientID": "different-client-id"}]
request_service_accounts.return_value = [{"clientId": "different-client-id"}]
user = User()
user.bearer_token = "mocked-bt"

Expand Down Expand Up @@ -1426,11 +1426,11 @@ def test_transform_incoming_payload(self) -> None:
result = self.it_service._transform_incoming_payload(service_account_from_it_service=it_service_account)

# Assert that the transformation was correct.
result_client_id = result["clientID"]
result_client_id = result["clientId"]
if not result_client_id:
self.fail('the "clientID" field is not present in the resulting model')
self.fail('the "clientId" field is not present in the resulting model')

self.assertEqual(client_id, result_client_id, 'the "clientID" field was not correctly transformed')
self.assertEqual(client_id, result_client_id, 'the "clientId" field was not correctly transformed')

result_name = result["name"]
if not result_name:
Expand Down Expand Up @@ -1474,9 +1474,9 @@ def test_merge_principals_it_service_accounts(self) -> None:
expected_first_username = f"{sa_client_id}-username"
expected_second_username = f"{sa_two_client_id}-username"
it_service_accounts = [
{"clientID": sa_client_id, "username": expected_first_username, "made_up_key": "made_up_value"},
{"clientID": sa_two_client_id, "username": expected_second_username, "made_up_key": "made_up_value"},
{"clientID": str(uuid.uuid4()), "username": "should-not-be-picked", "made_up_key": "made_up_value"},
{"clientId": sa_client_id, "username": expected_first_username, "made_up_key": "made_up_value"},
{"clientId": sa_two_client_id, "username": expected_second_username, "made_up_key": "made_up_value"},
{"clientId": str(uuid.uuid4()), "username": "should-not-be-picked", "made_up_key": "made_up_value"},
]

# Call the function under test.
Expand Down
10 changes: 5 additions & 5 deletions tests/management/principal/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ def test_read_principal_service_account_list_success(self, mock_request):

mock_request.return_value = [
{
"clientID": sa_client_id,
"clientId": sa_client_id,
"name": "service_account_name",
"description": "Service Account description",
"owner": "jsmith",
Expand All @@ -838,9 +838,9 @@ def test_read_principal_service_account_list_success(self, mock_request):
sa = response.data.get("data")[0]
self.assertCountEqual(
list(sa.keys()),
["clientID", "name", "description", "owner", "time_created", "type", "username"],
["clientId", "name", "description", "owner", "time_created", "type", "username"],
)
self.assertEqual(sa.get("clientID"), sa_client_id)
self.assertEqual(sa.get("clientId"), sa_client_id)
self.assertEqual(sa.get("name"), "service_account_name")
self.assertEqual(sa.get("description"), "Service Account description")
self.assertEqual(sa.get("owner"), "jsmith")
Expand All @@ -855,7 +855,7 @@ def test_read_principal_service_account_list_empty_response(self, mock_request):
sa_client_id = "026f5290-a3d3-013c-b93f-6aa2427b506c"
mock_request.return_value = [
{
"clientID": sa_client_id,
"clientId": sa_client_id,
"name": "service_account_name",
"description": "Service Account description",
"owner": "jsmith",
Expand Down Expand Up @@ -897,7 +897,7 @@ def test_read_principal_service_account_valid_limit_offset(self, mock_request):
for uuid in sa_client_ids:
mocked_values.append(
{
"clientID": uuid,
"clientId": uuid,
"name": f"service_account_name_{uuid.split('-')[0]}",
"description": f"Service Account description {uuid.split('-')[0]}",
"owner": "jsmith",
Expand Down

0 comments on commit 79c4b79

Please sign in to comment.