diff options
author | Christophe Henry <contact2@c-henry.fr> | 2021-10-08 15:33:09 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-12 06:59:46 +0200 |
commit | 4ff500f2948bfc332b3f4159021cad06e91943d3 (patch) | |
tree | c25360f4517ff62a85d2d8faa02b79a504c7ec41 /tests/auth_tests | |
parent | da266b3c5ca4bb7581d7a3cc51bc820e78cf64f0 (diff) | |
download | django-4ff500f2948bfc332b3f4159021cad06e91943d3.tar.gz |
Refs #21755 -- Fixed createsuperuser crash for required foreign keys passed in options in interactive mode.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/auth_tests')
-rw-r--r-- | tests/auth_tests/test_management.py | 26 |
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() |