mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 20:18:38 +02:00
Move unique logic from _get_requested_domain into fake_dot_gov, handle cases of missing phone or title
This commit is contained in:
parent
d032d76c75
commit
2b3ce1cdfb
3 changed files with 70 additions and 7 deletions
50
.github/workflows/load-fixtures.yaml
vendored
Normal file
50
.github/workflows/load-fixtures.yaml
vendored
Normal 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"
|
||||||
|
|
|
@ -104,7 +104,10 @@ class DomainRequestFixture:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fake_dot_gov(cls):
|
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
|
@classmethod
|
||||||
def fake_expiration_date(cls):
|
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:
|
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]
|
return DraftDomain.objects.get_or_create(name=request_dict["requested_domain"])[0]
|
||||||
|
|
||||||
# Generate a unique fake domain
|
# Generate a unique fake domain
|
||||||
# This will help us avoid domain already approved log warnings
|
return cls.fake_dot_gov()
|
||||||
while True:
|
|
||||||
fake_name = cls.fake_dot_gov()
|
|
||||||
if not Domain.objects.filter(name=fake_name).exists():
|
|
||||||
return DraftDomain.objects.create(name=fake_name)
|
|
||||||
return request.requested_domain
|
return request.requested_domain
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -327,8 +327,22 @@ class UserFixture:
|
||||||
# Update `is_staff` for existing users if necessary
|
# Update `is_staff` for existing users if necessary
|
||||||
users_to_update = []
|
users_to_update = []
|
||||||
for user in created_or_existing_users:
|
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:
|
if not user.is_staff:
|
||||||
user.is_staff = True
|
user.is_staff = True
|
||||||
|
updated = True
|
||||||
|
|
||||||
|
# Only append the user if any of the fields were updated
|
||||||
|
if updated:
|
||||||
users_to_update.append(user)
|
users_to_update.append(user)
|
||||||
|
|
||||||
# Save any users that were updated
|
# Save any users that were updated
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue