-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
resetdb
command and create test users and utility
- Loading branch information
1 parent
9000dd4
commit 9e79c8d
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |