comparison antispam/tests/utils_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/utils_tests.py@7c3816d76c6c
children 08d905e38a86
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
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