Mercurial > public > sg101
annotate gpp/antispam/tests/utils_tests.py @ 518:5171a5e9353b
For #194, add a celery task for purging deleted private messages.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 16 Dec 2011 01:17:35 +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 |