mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #33151 -- Fixed createsuperuser crash for many-to-many required fields in non-interactive mode.
This commit is contained in:
committed by
Mariusz Felisiak
parent
9be36f8044
commit
df2d2bc95c
@@ -994,6 +994,25 @@ class CreatesuperuserManagementCommandTestCase(TestCase):
|
||||
# Environment variables are ignored for non-required fields.
|
||||
self.assertEqual(user.first_name, '')
|
||||
|
||||
@override_settings(AUTH_USER_MODEL='auth_tests.CustomUserWithM2m')
|
||||
def test_environment_variable_m2m_non_interactive(self):
|
||||
new_io = StringIO()
|
||||
org_id_1 = Organization.objects.create(name='Organization 1').pk
|
||||
org_id_2 = Organization.objects.create(name='Organization 2').pk
|
||||
with mock.patch.dict(os.environ, {
|
||||
'DJANGO_SUPERUSER_ORGS': f'{org_id_1},{org_id_2}',
|
||||
}):
|
||||
call_command(
|
||||
'createsuperuser',
|
||||
interactive=False,
|
||||
username='joe',
|
||||
stdout=new_io,
|
||||
)
|
||||
command_output = new_io.getvalue().strip()
|
||||
self.assertEqual(command_output, 'Superuser created successfully.')
|
||||
user = CustomUserWithM2M._default_manager.get(username='joe')
|
||||
self.assertEqual(user.orgs.count(), 2)
|
||||
|
||||
@mock.patch.dict(os.environ, {
|
||||
'DJANGO_SUPERUSER_USERNAME': 'test_superuser',
|
||||
'DJANGO_SUPERUSER_EMAIL': 'joe@somewhere.org',
|
||||
|
||||
Reference in New Issue
Block a user