annotate gpp/antispam/tests/utils_tests.py @ 504:b5bd3509e6e6

Made some tweaks to the ajax login javascript. Cleared the inputs on failure so someone won't repeatedly try a bad login. Redirect on lockout so the page will refresh. Set focus on the username box after failure for convenience.
author Brian Neal <bgneal@gmail.com>
date Sat, 03 Dec 2011 16:25:15 +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