Skip to content

Commit

Permalink
Better support for django-admin options verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Oct 14, 2024
1 parent 60da4a3 commit 981d045
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tin/apps/users/management/commands/create_debug_users.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

import contextlib
from getpass import getpass

from django.core.management.base import BaseCommand
from django.core.management.base import BaseCommand, no_translations

import tin.tests.create_users as users

Expand All @@ -15,14 +14,15 @@ def add_arguments(self, parser):
parser.add_argument("--noinput", action="store_true", help="Do not ask for password")
parser.add_argument("--force", action="store_true", help="Force creation of users")

@no_translations
def handle(self, *args, **options):
if not options["noinput"]:
pwd = getpass("Enter password for all users: ")
else:
pwd = "jasongrace"

with (
contextlib.redirect_stdout(self.stdout), # type: ignore[misc]
contextlib.redirect_stderr(self.stderr), # type: ignore[misc]
):
users.add_users_to_database(password=pwd, verbose=True, force=options["force"])
users.add_users_to_database(
password=pwd,
verbose=options["verbosity"] > 0,
force=options["force"],
)
11 changes: 11 additions & 0 deletions tin/apps/users/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from __future__ import annotations

from django.contrib.auth import get_user_model
from django.core.management import call_command


def test_create_debug_users():
call_command("create_debug_users", noinput=True, verbosity=0)
assert get_user_model().objects.filter(username="admin", is_superuser=True)
assert get_user_model().objects.filter(username="student", is_student=True)
assert get_user_model().objects.filter(username="teacher", is_teacher=True)

0 comments on commit 981d045

Please sign in to comment.