Commit d7e12ea8a713ca2f3c788498e05764f3faad16ac
Committed by
Matheus de Sousa Faria
1 parent
d0240e4b
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
... | ... | @@ -14,9 +14,10 @@ from .utils import mailman |
14 | 14 | |
15 | 15 | class ColabUserManager(UserManager): |
16 | 16 | |
17 | - def _create_user(self, *args, **kwargs): | |
17 | + def _create_user(self, username, email, password, | |
18 | + is_staff, is_superuser, **kwargs): | |
19 | + args = (username, email, password, is_staff, is_superuser) | |
18 | 20 | user = super(ColabUserManager, self)._create_user(*args, **kwargs) |
19 | - password = kwargs.get('password') | |
20 | 21 | |
21 | 22 | user_created.send(user.__class__, user=user, password=password) |
22 | 23 | return user | ... | ... |
colab/accounts/tests/test_user.py
... | ... | @@ -426,3 +426,22 @@ class UserTest(TestCase): |
426 | 426 | self.authenticate_user() |
427 | 427 | response = self.client.get(url, follow=True) |
428 | 428 | self.assertIn(message, response.content) |
429 | + | |
430 | + @mock.patch('colab.accounts.signals.user_password_changed.send') | |
431 | + @mock.patch('colab.accounts.signals.user_created.send') | |
432 | + def test_user_created_signal(self, user_created_send, | |
433 | + user_password_changed_send): | |
434 | + user = User.objects.create_user( | |
435 | + username='test_user', | |
436 | + password='12345', | |
437 | + email='test@example.com', | |
438 | + ) | |
439 | + user_created_send.assert_called_with(User, user=user, password='12345') | |
440 | + user_password_changed_send.assert_not_called() | |
441 | + | |
442 | + @mock.patch('colab.accounts.signals.user_password_changed.send') | |
443 | + def test_user_password_changed_signal(self, user_password_changed_send): | |
444 | + user = User.objects.first() | |
445 | + user.set_password('54321') | |
446 | + user_password_changed_send.assert_called_with(User, user=user, | |
447 | + password='54321') | ... | ... |