Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding 'long_enough' built-in spam-checker
- Loading branch information
1 parent
55d249a
commit eb5e6ed
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Long enough spam checker backend for Zinnia""" | ||
from zinnia.settings import COMMENT_MIN_WORDS | ||
|
||
|
||
def backend(comment, content_object, request): | ||
"""Backend checking if the comment posted is long enough to be public. | ||
Generally a comments with few words is useless. The will avoid | ||
comments like this : | ||
- First ! | ||
- I don't like. | ||
- Check http://spam-ads.com/ | ||
""" | ||
return len(comment.comment.split()) < COMMENT_MIN_WORDS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Test cases for Zinnia's long_enought spam checker""" | ||
from django.test import TestCase | ||
from django.contrib import comments | ||
from django.contrib.auth.models import User | ||
from django.contrib.sites.models import Site | ||
|
||
from zinnia.models import Entry | ||
from zinnia.managers import PUBLISHED | ||
from zinnia.spam_checker.backends.long_enough import backend | ||
|
||
|
||
class LongEnoughTestCase(TestCase): | ||
"""Test cases for zinnia.spam_checker.long_enough""" | ||
|
||
def setUp(self): | ||
self.site = Site.objects.get_current() | ||
self.author = User.objects.create(username='admin', | ||
email='admin@example.com') | ||
|
||
params = {'title': 'My test entry', | ||
'content': 'My test entry', | ||
'slug': 'my-test-entry', | ||
'status': PUBLISHED} | ||
self.entry = Entry.objects.create(**params) | ||
self.entry.sites.add(self.site) | ||
self.entry.authors.add(self.author) | ||
|
||
def test_long_enough(self): | ||
comment = comments.get_model().objects.create( | ||
comment='My Comment', user=self.author, is_public=True, | ||
content_object=self.entry, site=self.site) | ||
self.assertEquals(backend(comment, self.entry, {}), True) | ||
|
||
comment.comment = 'Hello I just wanted to thank for great article' | ||
comment.save() | ||
self.assertEquals(backend(comment, self.entry, {}), False) |