revise while True

This commit is contained in:
Rachid Mrad 2024-11-26 11:54:11 -05:00
parent ff8a4a3fa1
commit e1ff54d264
No known key found for this signature in database

View file

@ -103,11 +103,13 @@ class DomainRequestFixture:
} }
@classmethod @classmethod
def fake_dot_gov(cls): def fake_dot_gov(cls, max_attempts=100):
while True: """Generate a unique .gov domain name without using an infinite loop."""
for _ in range(max_attempts):
fake_name = f"{fake.slug()}.gov" fake_name = f"{fake.slug()}.gov"
if not Domain.objects.filter(name=fake_name).exists(): if not Domain.objects.filter(name=fake_name).exists():
return DraftDomain.objects.create(name=fake_name) return DraftDomain.objects.create(name=fake_name)
raise RuntimeError(f"Failed to generate a unique .gov domain after {max_attempts} attempts")
@classmethod @classmethod
def fake_expiration_date(cls): def fake_expiration_date(cls):
@ -240,7 +242,7 @@ class DomainRequestFixture:
# Filter Suborganizations by the request's portfolio # Filter Suborganizations by the request's portfolio
portfolio_suborganizations = Suborganization.objects.filter(portfolio=request.portfolio) portfolio_suborganizations = Suborganization.objects.filter(portfolio=request.portfolio)
# Assuming SuborganizationFixture.SUBORGS is a list of dictionaries with a "name" key # Select a suborg that's defined in the fixtures
suborganization_names = [suborg["name"] for suborg in SuborganizationFixture.SUBORGS] suborganization_names = [suborg["name"] for suborg in SuborganizationFixture.SUBORGS]
# Further filter by names in suborganization_names # Further filter by names in suborganization_names