From b55df4c74a725a1df4efbce8163f995cb0bcd875 Mon Sep 17 00:00:00 2001 From: Christophe Henry Date: Fri, 8 Oct 2021 15:33:09 +0200 Subject: [4.0.x] Refs #21755 -- Fixed createsuperuser crash for required foreign keys passed in options in interactive mode. Co-authored-by: Mariusz Felisiak Backport of 4ff500f2948bfc332b3f4159021cad06e91943d3 from main --- tests/auth_tests/test_management.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') 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() -- cgit v1.3