Mercurial > public > sg101
annotate antispam/tests/utils_tests.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/antispam/tests/utils_tests.py@7c3816d76c6c |
children | 08d905e38a86 |
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 |