Move unique logic from _get_requested_domain into fake_dot_gov, handle cases of missing phone or title

This commit is contained in:
Rachid Mrad 2024-11-18 15:05:25 -05:00
parent d032d76c75
commit 2b3ce1cdfb
No known key found for this signature in database
3 changed files with 70 additions and 7 deletions

50
.github/workflows/load-fixtures.yaml vendored Normal file
View file

@ -0,0 +1,50 @@
# Manually load fixtures to an environment of choice.
name: Load fixtures
run-name: Manually load fixtures to sandbox of choice
on:
workflow_dispatch:
inputs:
environment:
description: Which environment should we load data for?
type: 'choice'
options:
- ab
- backup
- el
- cb
- dk
- es
- gd
- ko
- ky
- nl
- rb
- rh
- rjm
- meoward
- bob
- hotgov
- litterbox
- ms
- ad
- ag
jobs:
load-fixtures:
runs-on: ubuntu-latest
env:
CF_USERNAME: CF_${{ github.event.inputs.environment }}_USERNAME
CF_PASSWORD: CF_${{ github.event.inputs.environment }}_PASSWORD
steps:
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
- name: Load fake data for ${{ github.event.inputs.environment }}
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets[env.CF_USERNAME] }}
cf_password: ${{ secrets[env.CF_PASSWORD] }}
cf_org: cisa-dotgov
cf_space: ${{ github.event.inputs.environment }}
cf_command: "run-task getgov-${{ github.event.inputs.environment }} --command 'python manage.py load' --name loaddata"

View file

@ -104,7 +104,10 @@ class DomainRequestFixture:
@classmethod
def fake_dot_gov(cls):
return f"{fake.slug()}.gov"
while True:
fake_name = f"{fake.slug()}.gov"
if not Domain.objects.filter(name=fake_name).exists():
return DraftDomain.objects.create(name=fake_name)
@classmethod
def fake_expiration_date(cls):
@ -192,12 +195,8 @@ class DomainRequestFixture:
if "requested_domain" in request_dict and request_dict["requested_domain"] is not None:
return DraftDomain.objects.get_or_create(name=request_dict["requested_domain"])[0]
# Generate a unique fake domain
# This will help us avoid domain already approved log warnings
while True:
fake_name = cls.fake_dot_gov()
if not Domain.objects.filter(name=fake_name).exists():
return DraftDomain.objects.create(name=fake_name)
# Generate a unique fake domain
return cls.fake_dot_gov()
return request.requested_domain
@classmethod

View file

@ -327,8 +327,22 @@ class UserFixture:
# Update `is_staff` for existing users if necessary
users_to_update = []
for user in created_or_existing_users:
updated = False
if not user.title:
user.title = "Peon"
updated = True
if not user.phone:
user.phone = "2022222222"
updated = True
if not user.is_staff:
user.is_staff = True
updated = True
# Only append the user if any of the fields were updated
if updated:
users_to_update.append(user)
# Save any users that were updated