annotate gpp/antispam/tests/utils_tests.py @ 505:a5d11471d031

Refactor the logic in the rate limiter decorator. Check to see if the request was ajax, as the ajax view always returns 200. Have to decode the JSON response to see if an error occurred or not.
author Brian Neal <bgneal@gmail.com>
date Sat, 03 Dec 2011 19:13:38 +0000
parents 7c3816d76c6c
children
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