Add user fixtures

This commit is contained in:
Seamus Johnston 2022-10-12 11:46:45 -05:00
parent 72e92c9b54
commit 3e4279ace4
No known key found for this signature in database
GPG key ID: 2F21225985069105
5 changed files with 98 additions and 2 deletions

40
.github/workflows/loaddata.yaml vendored Normal file
View file

@ -0,0 +1,40 @@
name: Reset database
# This workflow can be run from the CLI
# gh workflow run loaddata.yaml -f environment=staging
# OR
# cf run-task getgov-staging --wait \
# --command 'python manage.py flush' --name flush
# cf run-task getgov-staging --wait \
# --command 'python manage.py loaddata registrar/fixtures/*' --name loaddata
on:
workflow_dispatch:
inputs:
environment:
type: choice
description: Where should we load data
options:
- staging
jobs:
reset-db-staging:
if: ${{ github.event.inputs.environment == 'staging' }}
runs-on: ubuntu-latest
steps:
- name: Delete existing data for staging
uses: 18f/cg-deploy-action@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: cisa-getgov-prototyping
cf_space: staging
full_command: "cf run-task getgov-staging --wait --command 'python manage.py flush' --name flush"
- name: Load fake data for staging
uses: 18f/cg-deploy-action@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: cisa-getgov-prototyping
cf_space: staging
full_command: "cf run-task getgov-staging --wait --command 'python manage.py loaddata registrar/fixtures/*' --name loaddata"

View file

@ -1,4 +1,4 @@
name: Run Migrations name: Run migrations
# This workflow can be run from the CLI # This workflow can be run from the CLI
# gh workflow run migrate.yaml -f environment=sandbox # gh workflow run migrate.yaml -f environment=sandbox

View file

@ -1,4 +1,4 @@
name: Security Checks name: Security checks
on: on:
push: push:

View file

@ -21,11 +21,27 @@ can manually run the task with
cf run-task getgov-unstable --command 'python manage.py migrate' --name migrate cf run-task getgov-unstable --command 'python manage.py migrate' --name migrate
``` ```
Optionally, load data from fixtures as well
```shell
cf run-task getgov-unstable --wait --command 'python manage.py loaddata registrar/fixtures/*' --name loaddata
```
For the `staging` environment, developers don't have credentials so we need to For the `staging` environment, developers don't have credentials so we need to
run that command using Github Actions. Go to run that command using Github Actions. Go to
<https://github.com/cisagov/getgov/actions/workflows/migrate.yaml> and select <https://github.com/cisagov/getgov/actions/workflows/migrate.yaml> and select
the "Run workflow" button, making sure that `staging` is selected. the "Run workflow" button, making sure that `staging` is selected.
## Getting data for fixtures
To run the `dumpdata` command, you'll need to ssh to a running container. `cf run-task` is useless for this, as you will not be able to see the output.
```shell
cf ssh getgov-unstable
/tmp/lifecycle/shell # this configures your environment
./manage.py dumpdata
```
## Dropping and re-creating the database ## Dropping and re-creating the database
For `unstable`, it might be necessary to start the database over from scratch. For `unstable`, it might be necessary to start the database over from scratch.

View file

@ -0,0 +1,40 @@
[
{
"model": "registrar.user",
"pk": 1,
"fields": {
"password": "",
"last_login": "2022-10-04T15:07:34.590Z",
"is_superuser": true,
"username": "c4a0e101-73b4-4d7d-9e5e-7f19a726a0fa",
"first_name": "Seamus",
"last_name": "Johnston",
"email": "",
"is_staff": true,
"is_active": true,
"date_joined": "2022-09-30T14:14:02.280Z",
"groups": [],
"user_permissions": []
}
},
{
"model": "registrar.userprofile",
"pk": 1,
"fields": {
"created_at": "2022-09-30T14:14:02.284Z",
"updated_at": "2022-10-04T15:07:34.593Z",
"street1": "",
"street2": "",
"street3": "",
"city": "",
"sp": "",
"pc": "",
"cc": "",
"voice": "",
"fax": "",
"email": "",
"user": 1,
"display_name": ""
}
}
]