Mercurial > public > sg101
annotate gpp/antispam/tests.py @ 235:d302c498560e
Fix problem when deleting multiple topics from a forum in bulk. We getting a list of topics from the database, then deleting each topic. But after you delete a topic, the forum.last_post on the remaining non-deleted topics can be stale. This was causing a weird DoesNotExist. Now just get the topics one at a time from the database.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 26 Aug 2010 04:01:58 +0000 |
parents | 28988cce138b |
children |
rev | line source |
---|---|
bgneal@214 | 1 """ |
bgneal@214 | 2 Tests for the antispam application. |
bgneal@214 | 3 """ |
bgneal@214 | 4 from django.test import TestCase |
bgneal@214 | 5 from django.core.cache import cache |
bgneal@214 | 6 |
bgneal@214 | 7 from antispam import SPAM_PHRASE_KEY |
bgneal@214 | 8 from antispam.models import SpamPhrase |
bgneal@214 | 9 from antispam.utils import contains_spam |
bgneal@214 | 10 |
bgneal@214 | 11 |
bgneal@214 | 12 class AntispamCase(TestCase): |
bgneal@214 | 13 |
bgneal@214 | 14 def test_no_phrases(self): |
bgneal@214 | 15 """ |
bgneal@214 | 16 Tests that an empty spam phrase table works. |
bgneal@214 | 17 """ |
bgneal@214 | 18 cache.delete(SPAM_PHRASE_KEY) |
bgneal@214 | 19 self.assertFalse(contains_spam("Here is some random text.")) |
bgneal@214 | 20 |
bgneal@214 | 21 def test_phrases(self): |
bgneal@214 | 22 """ |
bgneal@214 | 23 Simple test of some phrases. |
bgneal@214 | 24 """ |
bgneal@214 | 25 SpamPhrase.objects.create(phrase="grytner") |
bgneal@214 | 26 SpamPhrase.objects.create(phrase="allday.ru") |
bgneal@214 | 27 SpamPhrase.objects.create(phrase="stefa.pl") |
bgneal@214 | 28 |
bgneal@214 | 29 self.assert_(contains_spam("grytner")) |
bgneal@214 | 30 self.assert_(contains_spam("11grytner")) |
bgneal@214 | 31 self.assert_(contains_spam("11grytner>")) |
bgneal@214 | 32 self.assert_(contains_spam("1djkl jsd stefa.pl")) |
bgneal@214 | 33 self.assert_(contains_spam("1djkl jsd <stefa.pl---sd8")) |
bgneal@214 | 34 self.assert_(contains_spam("1dsdjallday.rukl jsd <stefa.pl---sd8")) |
bgneal@214 | 35 self.assert_(contains_spam(" 1djallday.rukl")) |
bgneal@214 | 36 self.assertFalse(contains_spam("this one is spam free.")) |
bgneal@214 | 37 |