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 08:08:05 +0200 |
commit | b1b26b37aff0c80d6abdf15c5ffdf0440a9a1d6a (patch) | |
tree | 8e75feea43d08752cfbec37ce106ce46d52874f0 /tests/auth_tests | |
parent | 57273e15699e2f87eda4d7cc1e3014c7d7c8f89a (diff) | |
download | django-b1b26b37aff0c80d6abdf15c5ffdf0440a9a1d6a.tar.gz |
Fixed #33178 -- Made createsuperuser validate required fields passed in options in interactive mode.
Diffstat (limited to 'tests/auth_tests')
-rw-r--r-- | tests/auth_tests/test_management.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index 3405e8588a..16da9eb4ad 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -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() |