def test_get_article_with_comment(self):
        """
        See if the comment renders
        """
        article = factories.create_article()
        comment = factories.create_comment(article=article, comment="Test-Comment")

        response = self.client.get(reverse('article-details', kwargs={"slug": article.slug}))
        self.assertContains(response, "Test-Comment", status_code=200)
    def test_admin_comments_access(self):
        """
        See that the admin renders
        """
        admin = User.objects.create_superuser('admin2', '*****@*****.**', 'secret')
        comment = factories.create_comment(user_name='Test-Name')

        self.client.login(username=admin.username, password='******')
        response = self.client.get(reverse('admin:fluent_comments_fluentcomment_changelist'))
        self.assertContains(response, ">Test-Name<", status_code=200)
    def test_moderator_no_akismet(self, *mocks):
        """
        Testing moderation without akismet
        """
        request = RequestFactory().post(reverse('comments-post-comment-ajax'))
        article = factories.create_article()
        comment = factories.create_comment(article=article)
        moderator = get_model_moderator(Article)  # type: FluentCommentsModerator

        self.assertTrue(article.enable_comments)
        self.assertFalse(moderator.akismet_check)
        self.assertTrue(moderator.allow(comment, article, request), "no akismet, comment should be allowed")
    def test_bad_words(self, *mocks):
        """
        Test moderation on bad words.
        """
        request = RequestFactory().post(reverse('comments-post-comment-ajax'))
        article = factories.create_article()
        comment = factories.create_comment(article=article, comment='Testing:viagra!!')
        moderator = get_model_moderator(Article)  # type: FluentCommentsModerator

        self.assertTrue(moderator.moderate_bad_words)  # see that settings are correctly patched
        self.assertTrue(moderator.moderate(comment, article, request), "bad_words should reject")

        comment.comment = "Just normal words"
        self.assertFalse(moderator.moderate(comment, article, request), "bad_words should not trigger")
    def test_akismet(self, *mocks):
        """
        Test an akismet call
        """
        request = RequestFactory().post(reverse('comments-post-comment-ajax'))
        article = factories.create_article()
        comment = factories.create_comment(article=article, user_name='viagra-test-123')
        moderator = get_model_moderator(Article)  # type: FluentCommentsModerator

        self.assertTrue(article.enable_comments)
        self.assertTrue(moderator.akismet_check)  # see that settings are correctly patched

        with patch.object(Akismet, '_request', return_value=MockedResponse(True)):
            self.assertTrue(moderator.moderate(comment, article, request), "akismet should reject")
    def test_akismet(self, *mocks):
        """
        Test an akismet call
        """
        request = RequestFactory().post(reverse('comments-post-comment-ajax'))
        article = factories.create_article()
        comment = factories.create_comment(article=article,
                                           user_name='viagra-test-123')
        moderator = get_model_moderator(Article)

        self.assertTrue(article.enable_comments)
        self.assertTrue(
            moderator.akismet_check)  # see that settings are correctly patched

        with patch.object(Akismet,
                          '_request',
                          return_value=MockedResponse(True)):
            self.assertTrue(moderator.moderate(comment, article, request),
                            "akismet should reject")
    def test_bad_words(self, *mocks):
        """
        Test moderation on bad words.
        """
        request = RequestFactory().post(reverse('comments-post-comment-ajax'))
        article = factories.create_article()
        comment = factories.create_comment(article=article,
                                           comment='Testing:viagra!!')
        moderator = get_model_moderator(
            Article)  # type: FluentCommentsModerator

        self.assertTrue(moderator.moderate_bad_words
                        )  # see that settings are correctly patched
        self.assertTrue(moderator.moderate(comment, article, request),
                        "bad_words should reject")

        comment.comment = "Just normal words"
        self.assertFalse(moderator.moderate(comment, article, request),
                         "bad_words should not trigger")