Mercurial > public > sg101
annotate 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 |
rev | line source |
---|---|
bgneal@934 | 1 """Tests for the antispam signal handlers.""" |
bgneal@934 | 2 import logging |
bgneal@934 | 3 |
bgneal@934 | 4 from django.contrib.auth.models import User |
bgneal@934 | 5 from django.test import Client |
bgneal@934 | 6 from django.test import TestCase |
bgneal@934 | 7 |
bgneal@934 | 8 from testfixtures import log_capture |
bgneal@934 | 9 |
bgneal@934 | 10 |
bgneal@934 | 11 class AntispamSignalRcvrTestCase(TestCase): |
bgneal@934 | 12 |
bgneal@934 | 13 def setUp(self): |
bgneal@934 | 14 self.user = User.objects.create_user('steve', 'steve@example.com', 'pwd') |
bgneal@934 | 15 self.client = Client() |
bgneal@934 | 16 |
bgneal@934 | 17 # Temporarily enable logging |
bgneal@934 | 18 self.old_disable = logging.getLogger().manager.disable |
bgneal@934 | 19 logging.disable(logging.NOTSET) |
bgneal@934 | 20 |
bgneal@934 | 21 def tearDown(self): |
bgneal@934 | 22 logging.disable(self.old_disable) |
bgneal@934 | 23 |
bgneal@934 | 24 @log_capture('auth') |
bgneal@934 | 25 def test_login_logout_callback(self, lc): |
bgneal@934 | 26 self.assertTrue(self.client.login(username='steve', password='pwd')) |
bgneal@934 | 27 self.client.logout() |
bgneal@934 | 28 lc.check(('auth', 'INFO', 'User login signal: steve'), |
bgneal@934 | 29 ('auth', 'INFO', 'User logout signal: steve')) |
bgneal@934 | 30 |
bgneal@934 | 31 @log_capture('auth') |
bgneal@934 | 32 def test_login_failed_callback(self, lc): |
bgneal@934 | 33 self.assertFalse(self.client.login(username='steve', password='xxx')) |
bgneal@934 | 34 lc.check(('auth', 'ERROR', |
bgneal@934 | 35 'User login failed signal from django.contrib.auth: steve')) |