mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-28 13:36:30 +02:00
Adjusted fixtures to allow specification of number of domain requests to load
This commit is contained in:
parent
8142daf3a6
commit
8432435c08
1 changed files with 35 additions and 13 deletions
|
@ -325,7 +325,11 @@ class DomainRequestFixture:
|
|||
@classmethod
|
||||
def _create_domain_requests(cls, users):
|
||||
"""Creates DomainRequests given a list of users."""
|
||||
total_domain_requests_to_make = 100000
|
||||
domain_requests_already_made = DomainRequest.objects.count()
|
||||
|
||||
domain_requests_to_create = []
|
||||
if domain_requests_already_made < total_domain_requests_to_make:
|
||||
for user in users:
|
||||
for request_data in cls.DOMAINREQUESTS:
|
||||
# Prepare DomainRequest objects
|
||||
|
@ -340,6 +344,24 @@ class DomainRequestFixture:
|
|||
except Exception as e:
|
||||
logger.warning(e)
|
||||
|
||||
num_additional_requests_to_make = total_domain_requests_to_make-domain_requests_already_made-len(domain_requests_to_create)
|
||||
if num_additional_requests_to_make > 0:
|
||||
for _ in range(num_additional_requests_to_make):
|
||||
random_user = random.choice(users)
|
||||
try:
|
||||
random_request_data = random.choice(cls.DOMAINREQUESTS)
|
||||
# Prepare DomainRequest objects
|
||||
domain_request = DomainRequest(
|
||||
creator=random_user,
|
||||
organization_name=random_request_data["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)
|
||||
domain_requests_to_create.append(domain_request)
|
||||
except Exception as e:
|
||||
logger.warning(f"Error creating random domain request: {e}")
|
||||
|
||||
|
||||
# Bulk create domain requests
|
||||
cls._bulk_create_requests(domain_requests_to_create)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue