Esempio n. 1
0
    def test_unicode(self):
        """
        Test Comment.__unicode__() method.
        """

        # Create Comment instance
        user = self._login()
        comment = Comment(EDID=self.edid, user=user, level=0, content='')
        comment.save()

        self.assertEqual(unicode(comment),
                         "%s: %s" % (comment.pk, comment.content[:100]))
Esempio n. 2
0
    def test_max_thread_level(self):
        """
        Test Comment.get_max_thread_level() method.
        """

        # Create Comment instance
        user = self._login()
        comment = Comment(EDID=self.edid, user=user, level=0, content='')

        self.assertEqual(comment.get_max_thread_level(), 2)

        with self.settings(EDID_COMMENT_MAX_THREAD_LEVEL=5):
            self.assertEqual(comment.get_max_thread_level(), 5)
Esempio n. 3
0
    def test_max_thread_level(self):
        """
        Test Comment.get_max_thread_level() method.
        """

        # Create Comment instance
        user = self._login()
        comment = Comment(EDID=self.edid, user=user, level=0, content='')

        self.assertEqual(comment.get_max_thread_level(), 2)

        with self.settings(EDID_COMMENT_MAX_THREAD_LEVEL=5):
            self.assertEqual(comment.get_max_thread_level(), 5)
Esempio n. 4
0
    def test_unicode(self):
        """
        Test Comment.__unicode__() method.
        """

        # Create Comment instance
        user = self._login()
        comment = Comment(EDID=self.edid, user=user, level=0, content='')
        comment.save()

        self.assertEqual(
            unicode(comment), "%s: %s" % (comment.pk, comment.content[:100])
        )
Esempio n. 5
0
    def test_str(self):
        """
        Test Comment.__str__() method.
        """

        # Create Comment instance
        user = self._login()
        comment = Comment(EDID=self.edid, user=user, level=0, content='')
        comment.save()

        # pylint: disable=unsubscriptable-object
        self.assertEqual(
            str(comment), "{}: {}".format(comment.pk, comment.content[:100])
        )
Esempio n. 6
0
    def test_parent(self):
        # Create nested comments up to the limit
        user = self._login()
        comment_1 = Comment(EDID=self.edid, user=user, level=0,
                            content='').save()
        comment_2 = Comment(EDID=self.edid, user=user, level=1,
                            parent=comment_1, content='').save()
        comment_3 = Comment(EDID=self.edid, user=user, level=2,
                            parent=comment_2, content='').save()

        # Try to submit comment with over-limit nesting
        data = self.valid_data
        data['parent'] = 3

        self._test_field_error(
            data, 'parent',
            u'Comment nesting limit exceeded.'
        )
Esempio n. 7
0
    def test_excessive_nesting(self):
        # Create nested comments up to the limit
        user = self._login()
        comment_1 = Comment(EDID=self.edid, user=user, level=0,
                            content='').save()
        comment_2 = Comment(EDID=self.edid, user=user, level=1,
                            parent=comment_1, content='').save()
        Comment(EDID=self.edid, user=user, level=2,
                parent=comment_2, content='').save()

        # Post comment with over-limit nesting
        data = self.valid_data
        data['parent'] = 3

        response = self.client.post(self.post_url, data)

        self.assertFormError(response, 'form', 'parent',
                             'Comment nesting limit exceeded.')
Esempio n. 8
0
    def test_get_comments(self):
        # Create nested comments
        user = self._login()
        comment_1 = Comment(EDID=self.edid, user=user, level=0, content='')
        comment_1.save()

        comment_2 = Comment(EDID=self.edid,
                            user=user,
                            level=1,
                            parent=comment_1,
                            content='')
        comment_2.save()

        comment_3 = Comment(EDID=self.edid, user=user, level=0, content='')
        comment_3.save()

        comment_4 = Comment(EDID=self.edid,
                            user=user,
                            level=2,
                            parent=comment_2,
                            content='')
        comment_4.save()

        # Get all comments for EDID
        comments = self.edid.get_comments()

        # Check comments are ordered
        self.assertEqual(comments, [{
            'comment':
            comment_1,
            'subcomments': [{
                'comment': comment_2,
                'subcomments': [{
                    'comment': comment_4
                }]
            }]
        }, {
            'comment': comment_3
        }])
Esempio n. 9
0
    def test_get_comments(self):
        # Create nested comments
        user = self._login()
        comment_1 = Comment(EDID=self.edid, user=user, level=0, content='')
        comment_1.save()

        comment_2 = Comment(EDID=self.edid, user=user, level=1,
                            parent=comment_1, content='')
        comment_2.save()

        comment_3 = Comment(EDID=self.edid, user=user, level=0, content='')
        comment_3.save()

        comment_4 = Comment(EDID=self.edid, user=user, level=2,
                            parent=comment_2, content='')
        comment_4.save()

        # Get all comments for EDID
        comments = self.edid.get_comments()

        # Check comments are ordered
        self.assertEqual(
            comments,
            [
                {'comment': comment_1,
                 'subcomments': [
                     {'comment': comment_2,
                      'subcomments': [{'comment': comment_4}]}
                 ]},
                {'comment': comment_3}
            ]
        )