1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #33178 -- Made createsuperuser validate required fields passed in options in interactive mode.

This commit is contained in:
Christophe Henry
2021-10-08 15:33:09 +02:00
committed by Mariusz Felisiak
parent 57273e1569
commit b1b26b37af
2 changed files with 25 additions and 0 deletions

View File

@@ -568,6 +568,29 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
verbosity=0,
)
@override_settings(AUTH_USER_MODEL='auth_tests.CustomUserWithFK')
def test_validate_fk_via_option_interactive(self):
email = Email.objects.create(email='mymail@gmail.com')
Group.objects.all().delete()
nonexistent_group_id = 1
msg = f'group instance with id {nonexistent_group_id} does not exist.'
@mock_inputs({
'password': 'nopasswd',
'Username (Email.id): ': email.pk,
'Email (Email.email): ': email.email,
})
def test(self):
with self.assertRaisesMessage(CommandError, msg):
call_command(
'createsuperuser',
group=nonexistent_group_id,
stdin=MockTTY(),
verbosity=0,
)
test(self)
@override_settings(AUTH_USER_MODEL='auth_tests.CustomUserWithM2m')
def test_fields_with_m2m(self):
new_io = StringIO()