comparison gpp/antispam/tests/utils_tests.py @ 472:7c3816d76c6c

Implement rate limiting on registration and login for #224.
author Brian Neal <bgneal@gmail.com>
date Thu, 25 Aug 2011 02:23:55 +0000
parents
children
comparison
equal deleted inserted replaced
471:d83296cac940 472:7c3816d76c6c
1 """
2 Tests for the antispam application.
3 """
4 from django.test import TestCase
5 from django.core.cache import cache
6
7 from antispam import SPAM_PHRASE_KEY
8 from antispam.models import SpamPhrase
9 from antispam.utils import contains_spam
10
11
12 class AntispamCase(TestCase):
13
14 def test_no_phrases(self):
15 """
16 Tests that an empty spam phrase table works.
17 """
18 cache.delete(SPAM_PHRASE_KEY)
19 self.assertFalse(contains_spam("Here is some random text."))
20
21 def test_phrases(self):
22 """
23 Simple test of some phrases.
24 """
25 SpamPhrase.objects.create(phrase="grytner")
26 SpamPhrase.objects.create(phrase="allday.ru")
27 SpamPhrase.objects.create(phrase="stefa.pl")
28
29 self.assert_(contains_spam("grytner"))
30 self.assert_(contains_spam("11grytner"))
31 self.assert_(contains_spam("11grytner>"))
32 self.assert_(contains_spam("1djkl jsd stefa.pl"))
33 self.assert_(contains_spam("1djkl jsd <stefa.pl---sd8"))
34 self.assert_(contains_spam("1dsdjallday.rukl jsd <stefa.pl---sd8"))
35 self.assert_(contains_spam(" 1djallday.rukl"))
36 self.assertFalse(contains_spam("this one is spam free."))
37