mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[4.0.x] Refs #21755 -- Fixed createsuperuser crash for required foreign keys passed in options in interactive mode.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Backport of 4ff500f294 from main
This commit is contained in:
committed by
Mariusz Felisiak
parent
224fa0bc7d
commit
b55df4c74a
@@ -505,6 +505,32 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
|
||||
|
||||
test(self)
|
||||
|
||||
@override_settings(AUTH_USER_MODEL='auth_tests.CustomUserWithFK')
|
||||
def test_fields_with_fk_via_option_interactive(self):
|
||||
new_io = StringIO()
|
||||
group = Group.objects.create(name='mygroup')
|
||||
email = Email.objects.create(email='mymail@gmail.com')
|
||||
|
||||
@mock_inputs({'password': 'nopasswd'})
|
||||
def test(self):
|
||||
call_command(
|
||||
'createsuperuser',
|
||||
interactive=True,
|
||||
username=email.pk,
|
||||
email=email.email,
|
||||
group=group.pk,
|
||||
stdout=new_io,
|
||||
stdin=MockTTY(),
|
||||
)
|
||||
|
||||
command_output = new_io.getvalue().strip()
|
||||
self.assertEqual(command_output, 'Superuser created successfully.')
|
||||
u = CustomUserWithFK._default_manager.get(email=email)
|
||||
self.assertEqual(u.username, email)
|
||||
self.assertEqual(u.group, group)
|
||||
|
||||
test(self)
|
||||
|
||||
@override_settings(AUTH_USER_MODEL='auth_tests.CustomUserWithM2m')
|
||||
def test_fields_with_m2m(self):
|
||||
new_io = StringIO()
|
||||
|
||||
Reference in New Issue
Block a user