comparison gpp/antispam/tests.py @ 214:28988cce138b

Implement #83: a string filter facility like NukeSeSentinel. It currently isn't hooked up to anything. Will do that in #84.
author Brian Neal <bgneal@gmail.com>
date Fri, 14 May 2010 02:19:48 +0000
parents
children
comparison
equal deleted inserted replaced
213:65016249bf35 214:28988cce138b
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