diff --git a/djangobb_forum/models.py b/djangobb_forum/models.py index bd6aaa5..0a726a2 100644 --- a/djangobb_forum/models.py +++ b/djangobb_forum/models.py @@ -588,6 +588,8 @@ class PostStatus(models.Model): MARKED_SPAM = 'marked_spam' MARKED_HAM = 'marked_ham' + AKISMET_MAX_SIZE = 1024*500 + post = models.OneToOneField(Post, db_index=True) state = FSMField(default=UNREVIEWED, db_index=True) topic = models.ForeignKey(Topic) # Original topic @@ -681,7 +683,7 @@ class PostStatus(models.Model): Truncate the post body to the largest allowed string size. Use size, not length, since the Akismet server checks size, not length. """ - return self.post.body.encode('utf-8')[:1024*500].decode('utf-8', 'ignore') + return self.post.body.encode('utf-8')[:self.AKISMET_MAX_SIZE].decode('utf-8', 'ignore') def _comment_check(self): """ diff --git a/djangobb_forum/tests/test_spam.py b/djangobb_forum/tests/test_spam.py index 925d225..6fea90c 100644 --- a/djangobb_forum/tests/test_spam.py +++ b/djangobb_forum/tests/test_spam.py @@ -154,13 +154,15 @@ class ForumSpamTests(TestCase): def test_content_truncated(self): """ Content larger than 0.5MB shouldn't be sent up to Akismet, which rejects - anything too big. + anything too big. For the test, we reduce the cap, since the test + database seems to have issues tearing down when that much data is present. """ - huge_content = ":lol:"*1024*1024 + huge_content = ":lol:"*1024 huge_post = Post.objects.create( topic=self.test_topic, user=self.user, body=huge_content, body_html="<p>%s</p>"%huge_content) huge_post_status = PostStatus.objects.create_for_post(huge_post) + huge_post_status.AKISMET_MAX_SIZE = 512 self.assertGreater(len(huge_content), len(huge_post_status.to_akismet_content())) def test_content_untruncated(self):