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