summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristophe Henry <contact2@c-henry.fr>2021-10-08 15:33:09 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-10-12 07:43:17 +0200
commitb55df4c74a725a1df4efbce8163f995cb0bcd875 (patch)
tree4ec57146b2f8f612d906f4fee5bba9048c71ff5a /tests
parent224fa0bc7de05f3f269e7fd41b66154b82a2e87f (diff)
[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 4ff500f2948bfc332b3f4159021cad06e91943d3 from main
Diffstat (limited to 'tests')
-rw-r--r--tests/auth_tests/test_management.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py
index 575975fd90..8cd7b378c0 100644
--- a/tests/auth_tests/test_management.py
+++ b/tests/auth_tests/test_management.py
@@ -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()