Skip to content

Commit

Permalink
Merge pull request RedHatInsights#1056 from petracihalova/uuid-fix
Browse files Browse the repository at this point in the history
refactor: improve usage of uuid package in tests
  • Loading branch information
lpichler authored Mar 6, 2024
2 parents a8f22a2 + e347f9f commit 040574f
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions tests/management/group/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
#
"""Test the group viewset."""
import random
import uuid
from unittest.mock import call, patch, ANY
from uuid import uuid4, UUID
from uuid import uuid4

from django.db import transaction
from django.conf import settings
Expand Down Expand Up @@ -2144,8 +2143,8 @@ def test_get_group_principals_check_service_account_ids(self):
group.save()

# Create some service accounts and add some of them to the group.
client_uuid_1 = uuid.uuid4()
client_uuid_2 = uuid.uuid4()
client_uuid_1 = uuid4()
client_uuid_2 = uuid4()

sa_1 = Principal.objects.create(
username=f"service-account-{client_uuid_1}",
Expand All @@ -2171,28 +2170,28 @@ def test_get_group_principals_check_service_account_ids(self):
# Create more service accounts that should not show in the results, since they're not going to be specified in
# the "client_ids" parameter.
Principal.objects.create(
username=f"service-account-{uuid.uuid4()}",
service_account_id=uuid.uuid4(),
username=f"service-account-{uuid4()}",
service_account_id=uuid4(),
type="service-account",
tenant=self.tenant,
)
Principal.objects.create(
username=f"service-account-{uuid.uuid4()}",
service_account_id=uuid.uuid4(),
username=f"service-account-{uuid4()}",
service_account_id=uuid4(),
type="service-account",
tenant=self.tenant,
)
Principal.objects.create(
username=f"service-account-{uuid.uuid4()}",
service_account_id=uuid.uuid4(),
username=f"service-account-{uuid4()}",
service_account_id=uuid4(),
type="service-account",
tenant=self.tenant,
)

# Create the UUIDs to be specified in the request.
not_in_group = uuid.uuid4()
not_in_group_2 = uuid.uuid4()
not_in_group_3 = uuid.uuid4()
not_in_group = uuid4()
not_in_group_2 = uuid4()
not_in_group_3 = uuid4()

# Also, create a set with the service accounts that will NOT go in the group to make it easier to assert that
# the results flag them as such.
Expand Down Expand Up @@ -2252,11 +2251,11 @@ def test_get_group_principals_check_service_account_ids_non_existent(self):
"""Test that when checking non-existent service account client IDs from another group the endpoint flags them as not present."""

# Create the UUIDs to be specified in the request.
not_in_group = uuid.uuid4()
not_in_group_2 = uuid.uuid4()
not_in_group_3 = uuid.uuid4()
not_in_group_4 = uuid.uuid4()
not_in_group_5 = uuid.uuid4()
not_in_group = uuid4()
not_in_group_2 = uuid4()
not_in_group_3 = uuid4()
not_in_group_4 = uuid4()
not_in_group_5 = uuid4()

# Also, create a set with the service accounts that will NOT go in the group to make it easier to assert that
# the results flag them as such.
Expand Down Expand Up @@ -2323,7 +2322,7 @@ def test_get_group_principals_check_service_account_ids_with_limit_offset(self):
group.save()

# Create a service account and it into group.
client_uuid = uuid.uuid4()
client_uuid = uuid4()
sa = Principal.objects.create(
username=f"service-account-{client_uuid}",
service_account_id=client_uuid,
Expand Down Expand Up @@ -2370,7 +2369,7 @@ def test_get_group_principals_check_service_account_ids_incompatible_query_param
for query_parameter in query_parameters_to_test:
url = (
f"{reverse('group-principals', kwargs={'uuid': self.group.uuid})}"
f"?service_account_client_ids={uuid.uuid4()}&{query_parameter}=abcde"
f"?service_account_client_ids={uuid4()}&{query_parameter}=abcde"
)
client = APIClient()
response: Response = client.get(url, **self.headers)
Expand Down

0 comments on commit 040574f

Please sign in to comment.