bgneal@472: """ bgneal@472: Tests for the antispam application. bgneal@472: """ bgneal@472: from django.test import TestCase bgneal@472: from django.core.cache import cache bgneal@472: bgneal@472: from antispam import SPAM_PHRASE_KEY bgneal@472: from antispam.models import SpamPhrase bgneal@472: from antispam.utils import contains_spam bgneal@472: bgneal@472: bgneal@472: class AntispamCase(TestCase): bgneal@472: bgneal@472: def test_no_phrases(self): bgneal@472: """ bgneal@472: Tests that an empty spam phrase table works. bgneal@472: """ bgneal@472: cache.delete(SPAM_PHRASE_KEY) bgneal@472: self.assertFalse(contains_spam("Here is some random text.")) bgneal@472: bgneal@472: def test_phrases(self): bgneal@472: """ bgneal@472: Simple test of some phrases. bgneal@472: """ bgneal@472: SpamPhrase.objects.create(phrase="grytner") bgneal@472: SpamPhrase.objects.create(phrase="allday.ru") bgneal@472: SpamPhrase.objects.create(phrase="stefa.pl") bgneal@472: bgneal@472: self.assert_(contains_spam("grytner")) bgneal@472: self.assert_(contains_spam("11grytner")) bgneal@472: self.assert_(contains_spam("11grytner>")) bgneal@472: self.assert_(contains_spam("1djkl jsd stefa.pl")) bgneal@472: self.assert_(contains_spam("1djkl jsd