Commit 8ffbce5e87350d4d63cb564d816370c4ca041447
1 parent
50dbc386
Exists in
master
and in
4 other branches
Added test cases for user sync signals
Showing
2 changed files
with
22 additions
and
2 deletions
Show diff stats
colab/accounts/models.py
| @@ -15,9 +15,10 @@ from .utils import mailman | @@ -15,9 +15,10 @@ from .utils import mailman | ||
| 15 | 15 | ||
| 16 | class ColabUserManager(UserManager): | 16 | class ColabUserManager(UserManager): |
| 17 | 17 | ||
| 18 | - def _create_user(self, *args, **kwargs): | 18 | + def _create_user(self, username, email, password, |
| 19 | + is_staff, is_superuser, **kwargs): | ||
| 20 | + args = (username, email, password, is_staff, is_superuser) | ||
| 19 | user = super(ColabUserManager, self)._create_user(*args, **kwargs) | 21 | user = super(ColabUserManager, self)._create_user(*args, **kwargs) |
| 20 | - password = kwargs.get('password') | ||
| 21 | 22 | ||
| 22 | user_created.send(user.__class__, user=user, password=password) | 23 | user_created.send(user.__class__, user=user, password=password) |
| 23 | return user | 24 | return user |
colab/accounts/tests/test_user.py
| @@ -374,3 +374,22 @@ class UserTest(TestCase): | @@ -374,3 +374,22 @@ class UserTest(TestCase): | ||
| 374 | self.authenticate_user() | 374 | self.authenticate_user() |
| 375 | self.validate_non_mandatory_fields('bio', '', ' ') | 375 | self.validate_non_mandatory_fields('bio', '', ' ') |
| 376 | self.user.delete() | 376 | self.user.delete() |
| 377 | + | ||
| 378 | + @mock.patch('colab.accounts.signals.user_password_changed.send') | ||
| 379 | + @mock.patch('colab.accounts.signals.user_created.send') | ||
| 380 | + def test_user_created_signal(self, user_created_send, | ||
| 381 | + user_password_changed_send): | ||
| 382 | + user = User.objects.create_user( | ||
| 383 | + username='test_user', | ||
| 384 | + password='12345', | ||
| 385 | + email='test@example.com', | ||
| 386 | + ) | ||
| 387 | + user_created_send.assert_called_with(User, user=user, password='12345') | ||
| 388 | + user_password_changed_send.assert_not_called() | ||
| 389 | + | ||
| 390 | + @mock.patch('colab.accounts.signals.user_password_changed.send') | ||
| 391 | + def test_user_password_changed_signal(self, user_password_changed_send): | ||
| 392 | + user = User.objects.first() | ||
| 393 | + user.set_password('54321') | ||
| 394 | + user_password_changed_send.assert_called_with(User, user=user, | ||
| 395 | + password='54321') |