comparison antispam/tests/test_receivers.py @ 934:9d6c2ed2f348

Add unit test for antispam signal handlers.
author Brian Neal <bgneal@gmail.com>
date Thu, 16 Apr 2015 20:49:19 -0500
parents
children 0cff6acf7d61
comparison
equal deleted inserted replaced
933:0aa9aeaa98a6 934:9d6c2ed2f348
1 """Tests for the antispam signal handlers."""
2 import logging
3
4 from django.contrib.auth.models import User
5 from django.test import Client
6 from django.test import TestCase
7
8 from testfixtures import log_capture
9
10
11 class AntispamSignalRcvrTestCase(TestCase):
12
13 def setUp(self):
14 self.user = User.objects.create_user('steve', 'steve@example.com', 'pwd')
15 self.client = Client()
16
17 # Temporarily enable logging
18 self.old_disable = logging.getLogger().manager.disable
19 logging.disable(logging.NOTSET)
20
21 def tearDown(self):
22 logging.disable(self.old_disable)
23
24 @log_capture('auth')
25 def test_login_logout_callback(self, lc):
26 self.assertTrue(self.client.login(username='steve', password='pwd'))
27 self.client.logout()
28 lc.check(('auth', 'INFO', 'User login signal: steve'),
29 ('auth', 'INFO', 'User logout signal: steve'))
30
31 @log_capture('auth')
32 def test_login_failed_callback(self, lc):
33 self.assertFalse(self.client.login(username='steve', password='xxx'))
34 lc.check(('auth', 'ERROR',
35 'User login failed signal from django.contrib.auth: steve'))