def test_email_reply(self): comment = Comment.objects.create(comment='My Comment 1', user=self.author, is_public=True, content_object=self.entry, site=self.site) moderator = EntryCommentModerator(Entry) moderator.email_notification_reply = True moderator.email_reply(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 0) comment = Comment.objects.create(comment='My Comment 2', user_email='*****@*****.**', content_object=self.entry, is_public=True, site=self.site) moderator.email_reply(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 0) comment = Comment.objects.create(comment='My Comment 3', user_email='*****@*****.**', content_object=self.entry, is_public=True, site=self.site) moderator.email_reply(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].to, [u'*****@*****.**']) comment = Comment.objects.create(comment='My Comment 4', user=self.author, is_public=True, content_object=self.entry, site=self.site) moderator.email_reply(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 2) self.assertEquals(mail.outbox[1].to, [u'*****@*****.**', u'*****@*****.**'])
def test_moderate_comment_on_entry_without_author(self): self.entry.authors.clear() comment = comments.get_model().objects.create( comment="My Comment", user=self.author, is_public=True, content_object=self.entry, site=self.site ) moderator = EntryCommentModerator(Entry) moderator.auto_moderate_comments = False moderator.spam_checker_backends = ("zinnia.spam_checker.backends.all_is_spam",) self.assertEquals(moderator.moderate(comment, self.entry, "request"), True)
def test_do_email_notification(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(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.mail_comment_notification_recipients = ['*****@*****.**'] moderator.do_email_notification(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 1)
def test_email(self): comment = Comment.objects.create(comment='My Comment', user=self.author, is_public=True, content_object=self.entry, site=self.site) self.assertEquals(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.email(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 1)
def test_moderate_comment_on_entry_without_author(self): self.entry.authors.clear() comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) moderator = EntryCommentModerator(Entry) moderator.auto_moderate_comments = False moderator.spam_checker_backends = ( 'zinnia.spam_checker.backends.all_is_spam',) self.assertTrue(moderator.moderate(comment, self.entry, 'request'))
def test_moderate(self): comment = Comment.objects.create(comment='My Comment', user=self.author, is_public=True, content_object=self.entry, site=self.site) moderator = EntryCommentModerator(Entry) moderator.auto_moderate_comments = True self.assertEquals(moderator.moderate(comment, self.entry, 'request'), True) moderator.auto_moderate_comments = False self.assertEquals(moderator.moderate(comment, self.entry, 'request'), False) # Because API key for Akismet is not defined
def test_moderate_comment_on_entry_without_author(self): self.entry.authors.clear() comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, site=self.site) moderator = EntryCommentModerator(Entry) moderator.auto_moderate_comments = False moderator.spam_checker_backends = ( 'zinnia.spam_checker.backends.all_is_spam',) self.assertEquals(moderator.moderate(comment, self.entry, 'request'), True) self.assertEquals(comments.get_model().objects.filter( flags__flag=SPAM).count(), 1)
def test_do_email_notification(self): comment = comments.get_model().objects.create( comment="My Comment", user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site, ) self.assertEqual(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.mail_comment_notification_recipients = ["*****@*****.**"] moderator.do_email_notification(comment, self.entry, "request") self.assertEqual(len(mail.outbox), 1)
def test_do_email_authors_without_email(self): """ https://github.com/Fantomas42/django-blog-zinnia/issues/145 """ comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) self.assertEqual(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.email_authors = True moderator.mail_comment_notification_recipients = [] contributor = Author.objects.create(username='******', email='*****@*****.**') self.entry.authors.add(contributor) moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) self.assertEqual(set(mail.outbox[0].to), set(['*****@*****.**', '*****@*****.**'])) mail.outbox = [] contributor.email = '' contributor.save() moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, ['*****@*****.**'])
def test_do_email_authors_without_email(self): """ https://github.com/Fantomas42/django-blog-zinnia/issues/145 """ comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) self.assertEqual(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.email_authors = True moderator.mail_comment_notification_recipients = [] contributor = Author.objects.create(username='******', email='*****@*****.**') self.entry.authors.add(contributor) moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) #This test, as written, is flawed. It assumes that the database #returns the message's authors in the order they were added, #which is an invalid assumption. #For now, I'm changing the test. An alternative fix would be to add an #order(ing?) attribute in Author.Meta . self.assertEqual(set(mail.outbox[0].to), set(['*****@*****.**', '*****@*****.**'])) mail.outbox = [] contributor.email = '' contributor.save() moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, ['*****@*****.**'])
def test_moderate_comment_on_entry_without_author(self): self.entry.authors.clear() comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, site=self.site) moderator = EntryCommentModerator(Entry) moderator.auto_moderate_comments = False moderator.spam_checker_backends = ( 'zinnia.spam_checker.backends.all_is_spam', ) self.assertEquals(moderator.moderate(comment, self.entry, 'request'), True) self.assertEquals( comments.get_model().objects.filter(flags__flag=SPAM).count(), 1)
def test_do_email_authors_without_email(self): """ https://github.com/Fantomas42/django-blog-zinnia/issues/145 """ comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) self.assertEqual(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.email_authors = True moderator.mail_comment_notification_recipients = [] contributor = Author.objects.create(username='******', email='*****@*****.**') self.entry.authors.add(contributor) moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) #This test, as written, is flawed. It assumes that the database #returns the message's authors in the order they were added, #which is an invalid assumption. #For now, I'm changing the test. An alternative fix would be to add an #order(ing?) attribute in Author.Meta . self.assertEqual( set(mail.outbox[0].to), set(['*****@*****.**', '*****@*****.**'])) mail.outbox = [] contributor.email = '' contributor.save() moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, ['*****@*****.**'])
def test_do_email_authors_without_email(self): """ https://github.com/Fantomas42/django-blog-zinnia/issues/145 """ comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) self.assertEqual(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.email_authors = True moderator.mail_comment_notification_recipients = [] contributor = Author.objects.create(username='******', email='*****@*****.**') self.entry.authors.add(contributor) moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) self.assertEqual( set(mail.outbox[0].to), set(['*****@*****.**', '*****@*****.**'])) mail.outbox = [] contributor.email = '' contributor.save() moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].to, ['*****@*****.**'])
def test_do_email_authors(self): comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) self.assertEqual(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.email_authors = True moderator.mail_comment_notification_recipients = [ '*****@*****.**', '*****@*****.**'] moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 0) moderator.mail_comment_notification_recipients = [] moderator.do_email_authors(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1)
def test_do_email_authors(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(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.email_authors = True moderator.mail_comment_notification_recipients = [u"*****@*****.**", u"*****@*****.**"] moderator.do_email_authors(comment, self.entry, "request") self.assertEquals(len(mail.outbox), 0) moderator.mail_comment_notification_recipients = [] moderator.do_email_authors(comment, self.entry, "request") self.assertEquals(len(mail.outbox), 1)
def test_moderate(self): comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, site=self.site) moderator = EntryCommentModerator(Entry) moderator.auto_moderate_comments = True moderator.spam_checker_backends = () self.assertEquals(moderator.moderate(comment, self.entry, 'request'), True) moderator.auto_moderate_comments = False self.assertEquals(moderator.moderate(comment, self.entry, 'request'), False) moderator.spam_checker_backends = ( 'zinnia.spam_checker.backends.all_is_spam', ) self.assertEquals(moderator.moderate(comment, self.entry, 'request'), True)
def test_moderate(self): comment = comments.get_model().objects.create( comment='My Comment', user=self.author, is_public=True, content_object=self.entry, site=self.site) moderator = EntryCommentModerator(Entry) moderator.auto_moderate_comments = True moderator.spam_checker_backends = () self.assertEquals(moderator.moderate(comment, self.entry, 'request'), True) moderator.auto_moderate_comments = False self.assertEquals(moderator.moderate(comment, self.entry, 'request'), False) moderator.spam_checker_backends = ( 'zinnia.spam_checker.backends.all_is_spam',) self.assertEquals(moderator.moderate(comment, self.entry, 'request'), True)
def test_moderate(self): comment = comments.get_model().objects.create( comment="My Comment", user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site, ) moderator = EntryCommentModerator(Entry) moderator.auto_moderate_comments = True moderator.spam_checker_backends = () self.assertTrue(moderator.moderate(comment, self.entry, "request")) moderator.auto_moderate_comments = False self.assertFalse(moderator.moderate(comment, self.entry, "request")) moderator.spam_checker_backends = ("zinnia.spam_checker.backends.all_is_spam",) self.assertTrue(moderator.moderate(comment, self.entry, "request"))
def test_do_email_authors_without_email(self): """ https://github.com/Fantomas42/django-blog-zinnia/issues/145 """ comment = comments.get_model().objects.create( comment="My Comment", user=self.author, is_public=True, content_object=self.entry, site=self.site ) self.assertEquals(len(mail.outbox), 0) moderator = EntryCommentModerator(Entry) moderator.email_authors = True moderator.mail_comment_notification_recipients = [] contributor = Author.objects.create(username="******", email="*****@*****.**") self.entry.authors.add(contributor) moderator.do_email_authors(comment, self.entry, "request") self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].to, [u"*****@*****.**", u"*****@*****.**"]) mail.outbox = [] contributor.email = "" contributor.save() moderator.do_email_authors(comment, self.entry, "request") self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].to, [u"*****@*****.**"])
def test_do_email_reply(self): comment = comments.get_model().objects.create( comment='My Comment 1', user=self.author, is_public=True, content_object=self.entry, site=self.site) moderator = EntryCommentModerator(Entry) moderator.email_notification_reply = True moderator.mail_comment_notification_recipients = [ u'*****@*****.**', u'*****@*****.**'] moderator.do_email_reply(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 0) comment = comments.get_model().objects.create( comment='My Comment 2', user_email='*****@*****.**', content_object=self.entry, is_public=True, site=self.site) moderator.do_email_reply(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 0) comment = comments.get_model().objects.create( comment='My Comment 3', user_email='*****@*****.**', content_object=self.entry, is_public=True, site=self.site) moderator.do_email_reply(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].bcc, [u'*****@*****.**']) comment = comments.get_model().objects.create( comment='My Comment 4', user=self.author, is_public=True, content_object=self.entry, site=self.site) moderator.do_email_reply(comment, self.entry, 'request') self.assertEquals(len(mail.outbox), 2) self.assertEquals(mail.outbox[1].bcc, [u'*****@*****.**', u'*****@*****.**'])
def test_do_email_reply(self): comment = comments.get_model().objects.create( comment='My Comment 1', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) moderator = EntryCommentModerator(Entry) moderator.email_notification_reply = True moderator.mail_comment_notification_recipients = [ '*****@*****.**', '*****@*****.**' ] moderator.do_email_reply(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 0) comment = comments.get_model().objects.create( comment='My Comment 2', user_email='*****@*****.**', content_object=self.entry, is_public=True, submit_date=timezone.now(), site=self.site) moderator.do_email_reply(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 0) comment = comments.get_model().objects.create( comment='My Comment 3', user_email='*****@*****.**', content_object=self.entry, is_public=True, submit_date=timezone.now(), site=self.site) moderator.do_email_reply(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].bcc, ['*****@*****.**']) comment = comments.get_model().objects.create( comment='My Comment 4', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) moderator.do_email_reply(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 2) #This suffers from the same ordering assumption issue self.assertEqual(set(mail.outbox[1].bcc), set(['*****@*****.**', '*****@*****.**']))
def test_do_email_reply(self): comment = comments.get_model().objects.create( comment='My Comment 1', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) moderator = EntryCommentModerator(Entry) moderator.email_notification_reply = True moderator.mail_comment_notification_recipients = [ '*****@*****.**', '*****@*****.**'] moderator.do_email_reply(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 0) comment = comments.get_model().objects.create( comment='My Comment 2', user_email='*****@*****.**', content_object=self.entry, is_public=True, submit_date=timezone.now(), site=self.site) moderator.do_email_reply(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 0) comment = comments.get_model().objects.create( comment='My Comment 3', user_email='*****@*****.**', content_object=self.entry, is_public=True, submit_date=timezone.now(), site=self.site) moderator.do_email_reply(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].bcc, ['*****@*****.**']) comment = comments.get_model().objects.create( comment='My Comment 4', user=self.author, is_public=True, content_object=self.entry, submit_date=timezone.now(), site=self.site) moderator.do_email_reply(comment, self.entry, 'request') self.assertEqual(len(mail.outbox), 2) self.assertEqual( set(mail.outbox[1].bcc), set(['*****@*****.**', '*****@*****.**']))
def test_do_email_reply(self): comment = comments.get_model().objects.create( comment="My Comment 1", user=self.author, is_public=True, content_object=self.entry, site=self.site ) moderator = EntryCommentModerator(Entry) moderator.email_notification_reply = True moderator.mail_comment_notification_recipients = [u"*****@*****.**", u"*****@*****.**"] moderator.do_email_reply(comment, self.entry, "request") self.assertEquals(len(mail.outbox), 0) comment = comments.get_model().objects.create( comment="My Comment 2", user_email="*****@*****.**", content_object=self.entry, is_public=True, site=self.site, ) moderator.do_email_reply(comment, self.entry, "request") self.assertEquals(len(mail.outbox), 0) comment = comments.get_model().objects.create( comment="My Comment 3", user_email="*****@*****.**", content_object=self.entry, is_public=True, site=self.site, ) moderator.do_email_reply(comment, self.entry, "request") self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].bcc, [u"*****@*****.**"]) comment = comments.get_model().objects.create( comment="My Comment 4", user=self.author, is_public=True, content_object=self.entry, site=self.site ) moderator.do_email_reply(comment, self.entry, "request") self.assertEquals(len(mail.outbox), 2) self.assertEquals(mail.outbox[1].bcc, [u"*****@*****.**", u"*****@*****.**"])