annotate antispam/tests/utils_tests.py @ 583:9dbd9a2a76d6

Update production requirements.txt after Django 1.4 upgrade.
author Brian Neal <bgneal@gmail.com>
date Sun, 06 May 2012 11:03:38 -0500
parents ee87ea74d46b
children 08d905e38a86
rev   line source
bgneal@472 1 """
bgneal@472 2 Tests for the antispam application.
bgneal@472 3 """
bgneal@472 4 from django.test import TestCase
bgneal@472 5 from django.core.cache import cache
bgneal@472 6
bgneal@472 7 from antispam import SPAM_PHRASE_KEY
bgneal@472 8 from antispam.models import SpamPhrase
bgneal@472 9 from antispam.utils import contains_spam
bgneal@472 10
bgneal@472 11
bgneal@472 12 class AntispamCase(TestCase):
bgneal@472 13
bgneal@472 14 def test_no_phrases(self):
bgneal@472 15 """
bgneal@472 16 Tests that an empty spam phrase table works.
bgneal@472 17 """
bgneal@472 18 cache.delete(SPAM_PHRASE_KEY)
bgneal@472 19 self.assertFalse(contains_spam("Here is some random text."))
bgneal@472 20
bgneal@472 21 def test_phrases(self):
bgneal@472 22 """
bgneal@472 23 Simple test of some phrases.
bgneal@472 24 """
bgneal@472 25 SpamPhrase.objects.create(phrase="grytner")
bgneal@472 26 SpamPhrase.objects.create(phrase="allday.ru")
bgneal@472 27 SpamPhrase.objects.create(phrase="stefa.pl")
bgneal@472 28
bgneal@472 29 self.assert_(contains_spam("grytner"))
bgneal@472 30 self.assert_(contains_spam("11grytner"))
bgneal@472 31 self.assert_(contains_spam("11grytner>"))
bgneal@472 32 self.assert_(contains_spam("1djkl jsd stefa.pl"))
bgneal@472 33 self.assert_(contains_spam("1djkl jsd <stefa.pl---sd8"))
bgneal@472 34 self.assert_(contains_spam("1dsdjallday.rukl jsd <stefa.pl---sd8"))
bgneal@472 35 self.assert_(contains_spam(" 1djallday.rukl"))
bgneal@472 36 self.assertFalse(contains_spam("this one is spam free."))
bgneal@472 37