def test_comment_filters(self): GemSettings.objects.create(site_id=Main.objects.first().get_site().pk, banned_keywords_and_patterns='naughty') form_data = self.getValidData(self.article) # check if user has typed in a number comment_form = MoloCommentForm(self.article, data=dict(form_data, comment="0821111111")) self.assertFalse(comment_form.is_valid()) # check if user has typed in an email address comment_form = MoloCommentForm(self.article, data=dict(form_data, comment="*****@*****.**")) self.assertFalse(comment_form.is_valid()) # check if user has used a banned keyword comment_form = MoloCommentForm(self.article, data=dict(form_data, comment="naughty")) self.assertFalse(comment_form.is_valid())
def test_molo_post_comment(self): data = MoloCommentForm(self.user, {}).generate_security_data() data.update({ 'name': 'the supplied name', 'comment': 'Foo', }) self.client.post( reverse('molo.commenting:molo-comments-post'), data) [comment] = MoloComment.objects.filter(user=self.user) self.assertEqual(comment.comment, 'Foo') self.assertEqual(comment.user_name, 'the supplied name')
def test_anonymous_comment_with_alias(self): self.client.login(username='******', password='******') self.user.profile.alias = 'this is my alias' self.user.profile.save() data = MoloCommentForm(self.user, {}).generate_security_data() data.update({ 'comment': 'Foo', 'submit_anonymously': '1', }) self.client.post(reverse('molo.commenting:molo-comments-post'), data) comment = MoloComment.objects.filter(user=self.user).first() self.assertEqual(comment.comment, 'Foo') self.assertEqual(comment.user_name, 'Anonymous')
def test_molo_post_comment_without_email_address(self): self.user.email = '' self.user.save() data = MoloCommentForm(self.user, {}).generate_security_data() data.update({ 'name': 'the supplied name', 'comment': 'Foo', }) self.client.post( reverse('molo.commenting:molo-comments-post'), data) [comment] = MoloComment.objects.filter(user=self.user) self.assertEqual(comment.comment, 'Foo') self.assertEqual(comment.user_name, 'the supplied name') self.assertEqual(comment.user_email, '*****@*****.**')
def test_commenting_open(self): article = ArticlePage.objects.create( title='article 1', depth=1, subtitle='article 1 subtitle', slug='article-1', path=[1], commenting_state='O') article.save() initial = { 'object_pk': article.id, 'content_type': "core.articlepage" } data = MoloCommentForm(article, {}, initial=initial).generate_security_data() data.update({ 'comment': "This is a second comment", }) response = self.client.post( reverse('molo.commenting:molo-comments-post'), data) self.assertEqual(response.status_code, 302)
def getValidData(self, obj): form = MoloCommentForm(obj) form_data = self.getData() form_data.update(form.initial) return form_data