mirror of
https://github.com/django/django.git
synced 2025-10-26 23:26:08 +00:00
Fixed #20541 -- don't raise db signals twice when creating superuser
This commit is contained in:
committed by
Tim Graham
parent
5005303ae7
commit
cab333cb16
@@ -5,6 +5,7 @@ from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable,
|
||||
UserManager)
|
||||
from django.contrib.auth.tests.utils import skipIfCustomUser
|
||||
from django.db.models.signals import post_save
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.utils import six
|
||||
@@ -140,3 +141,27 @@ class IsActiveTestCase(TestCase):
|
||||
user_fetched = UserModel._default_manager.get(pk=user.pk)
|
||||
# the attribute is always true for newly retrieved instance
|
||||
self.assertEqual(user_fetched.is_active, True)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class TestCreateSuperUserSignals(TestCase):
|
||||
"""
|
||||
Simple test case for ticket #20541
|
||||
"""
|
||||
def post_save_listener(self, *args, **kwargs):
|
||||
self.signals_count += 1
|
||||
|
||||
def setUp(self):
|
||||
self.signals_count = 0
|
||||
post_save.connect(self.post_save_listener, sender=User)
|
||||
|
||||
def tearDown(self):
|
||||
post_save.disconnect(self.post_save_listener, sender=User)
|
||||
|
||||
def test_create_user(self):
|
||||
User.objects.create_user("JohnDoe")
|
||||
self.assertEqual(self.signals_count, 1)
|
||||
|
||||
def test_create_superuser(self):
|
||||
User.objects.create_superuser("JohnDoe", "mail@example.com", "1")
|
||||
self.assertEqual(self.signals_count, 1)
|
||||
|
||||
Reference in New Issue
Block a user