bgneal@472: """ bgneal@472: Tests for the antispam application. bgneal@625: bgneal@472: """ bgneal@625: import datetime bgneal@625: bgneal@472: from django.test import TestCase bgneal@625: from django.contrib.auth.models import User bgneal@625: from django.contrib.contenttypes.models import ContentType 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@625: from antispam.utils import contains_spam, deactivate_spammer bgneal@625: bgneal@625: from comments.models import Comment bgneal@625: from polls.models import Poll bgneal@625: from elsewhere.models import WebsiteProfile bgneal@625: from shoutbox.models import Shout bgneal@625: from bio.models import STA_SPAMMER 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@625: 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@625: 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