Mercurial > public > sg101
comparison antispam/tests/rate_limit_tests.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/antispam/tests/rate_limit_tests.py@6f5fff924877 |
children |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """ | |
2 Tests for the rate limiting function in the antispam application. | |
3 | |
4 """ | |
5 from django.test import TestCase | |
6 from django.core.urlresolvers import reverse | |
7 | |
8 from antispam.rate_limit import _make_key | |
9 from core.services import get_redis_connection | |
10 | |
11 | |
12 class RateLimitTestCase(TestCase): | |
13 KEY = _make_key('127.0.0.1') | |
14 | |
15 def setUp(self): | |
16 self.conn = get_redis_connection() | |
17 self.conn.delete(self.KEY) | |
18 | |
19 def tearDown(self): | |
20 self.conn.delete(self.KEY) | |
21 | |
22 def testRegistrationLockout(self): | |
23 | |
24 for i in range(1, 11): | |
25 response = self.client.post( | |
26 reverse('accounts-register'), | |
27 {}, | |
28 follow=True) | |
29 | |
30 if i < 10: | |
31 self.assertEqual(response.status_code, 200) | |
32 self.assertTemplateUsed(response, 'accounts/register.html') | |
33 elif i >= 10: | |
34 self.assertEqual(response.status_code, 403) | |
35 self.assertTemplateUsed(response, 'antispam/blocked.html') | |
36 | |
37 def testLoginLockout(self): | |
38 | |
39 for i in range(1, 11): | |
40 response = self.client.post( | |
41 reverse('accounts-login'), | |
42 {}, | |
43 follow=True) | |
44 | |
45 if i < 10: | |
46 self.assertEqual(response.status_code, 200) | |
47 self.assertTemplateUsed(response, 'accounts/login.html') | |
48 elif i >= 10: | |
49 self.assertEqual(response.status_code, 403) | |
50 self.assertTemplateUsed(response, 'antispam/blocked.html') | |
51 | |
52 def testHoneypotLockout(self): | |
53 | |
54 response = self.client.post( | |
55 reverse('accounts-register'), { | |
56 'username': u'test_user', | |
57 'email': u'test_user@example.com', | |
58 'password1': u'password', | |
59 'password2': u'password', | |
60 'agree_age': u'on', | |
61 'agree_tos': u'on', | |
62 'agree_privacy': u'on', | |
63 'question1': u'101', | |
64 'question2': u'DsjkdE$', | |
65 }, | |
66 follow=True) | |
67 | |
68 val = self.conn.get(self.KEY) | |
69 self.assertEqual(val, '1000001') | |
70 | |
71 response = self.client.post( | |
72 reverse('accounts-login'), | |
73 {}, | |
74 follow=True) | |
75 | |
76 self.assertEqual(response.status_code, 403) | |
77 self.assertTemplateUsed(response, 'antispam/blocked.html') |