Skip to content

Commit

Permalink
Add resetdb command and create test users and utility
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Sep 20, 2022
1 parent 9000dd4 commit 9e79c8d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ all scripts should be run from the host.
| `console` | Run interactive shell inside application container |
| `lint` | Lint source code |
| `server` | Run Docker Compose services |
| `setup` | Provision Vagrant VM and run `update` |
| `setup` | Provision Vagrant VM and run `update` and `resetdb` |
| `test` | Run unit tests |
| `update` | Build Docker images |
| `resetdb` | Restore development database to defaults (with test data) |

### Adding NPM Packages

Expand Down
27 changes: 27 additions & 0 deletions scripts/resetdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e

if [[ -n "${IOW_BOUNDARY_TOOL_DEBUG}" ]]; then
set -x
fi

function usage() {
echo -n \
"Usage: $(basename "$0")
Reset database and repopulate with test utilities and users.
"
}

function resetdb() {
./scripts/manage resetdb
}

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
if [ "${1:-}" = "--help" ]; then
usage
else
resetdb
fi
fi

1 change: 1 addition & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then

./scripts/bootstrap
./scripts/update
./scripts/resetdb
else
usage
fi
Expand Down
33 changes: 33 additions & 0 deletions src/django/api/management/commands/resetdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.core.management import call_command
from django.core.management.base import BaseCommand

from api.models import Role, Utility, User


class Command(BaseCommand):
help = "Reset the DB schema, run migrations, and create test data."

def handle(self, *args, **options):
call_command("reset_schema", "--noinput")
call_command("migrate")

# Create test utility located in Raleigh.
test_utility = Utility(pwsid="123456789", name="Azavea Test Utility")
test_utility.save()

# Create test users.
User.objects.create_superuser(
email="[email protected]",
password="password",
)
User.objects.create_user(
email="[email protected]",
password="password",
role=Role.objects.get(description="VALIDATOR"),
)
User.objects.create_user(
email="[email protected]",
password="password",
role=Role.objects.get(description="CONTRIBUTOR"),
utility=test_utility,
)

0 comments on commit 9e79c8d

Please sign in to comment.