Skip to content

Commit

Permalink
cleanup in fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
CocoByte committed Jan 15, 2025
1 parent f858571 commit e276f45
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/registrar/fixtures/fixtures_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ def load(cls):
def _create_domain_requests(cls, users):
"""Creates DomainRequests given a list of users."""
total_domain_requests_to_make = 1000

# Check if the database is already populated with the desired
# number of entries.
# (Prevents re-adding more entries to an already populated database,
# which happens when restarting Docker src)
domain_requests_already_made = DomainRequest.objects.count()

domain_requests_to_create = []
Expand All @@ -349,14 +354,14 @@ def _create_domain_requests(cls, users):
for _ in range(num_additional_requests_to_make):
random_user = random.choice(users)
try:
random_request_data = random.choice(cls.DOMAINREQUESTS)
random_request_type = random.choice(cls.DOMAINREQUESTS)
# Prepare DomainRequest objects
domain_request = DomainRequest(
creator=random_user,
organization_name=random_request_data["organization_name"],
organization_name=random_request_type["organization_name"],
)
cls._set_non_foreign_key_fields(domain_request, random_request_data)
cls._set_foreign_key_fields(domain_request, random_request_data, random_user)
cls._set_non_foreign_key_fields(domain_request, random_request_type)
cls._set_foreign_key_fields(domain_request, random_request_type, random_user)
domain_requests_to_create.append(domain_request)
except Exception as e:
logger.warning(f"Error creating random domain request: {e}")
Expand Down

0 comments on commit e276f45

Please sign in to comment.