コード例 #1
0
 def test_render_content(self):
     comment = self.parent_comment_1
     comment.content = "Any long text just for testing render content function"
     comment.save()
     content_words = comment.content.split(' ')
     self.assertEqual(len(content_words), 9)
     # truncate number is bigger than content words
     result = render_content(comment.content, 10)
     self.assertEqual(result['text_1'], comment.content)
     self.assertIsNone(result['text_2'])
     # truncate number is smaller than content words
     result = render_content(comment.content, 5)
     self.assertEqual(result['text_1'], ' '.join(content_words[:5]))
     self.assertEqual(result['text_2'], ' '.join(content_words[5:]))
コード例 #2
0
    def test_content_wrapping_with_large_truncate_number(self):
        content_words = self.comment.content.split()
        self.assertIs(len(content_words) < 20, True)

        result = render_content(self.comment)

        self.assertEqual(result['text_1'], self.comment.content)
        self.assertIsNone(result['text_2'])
コード例 #3
0
    def test_multiple_line_breaks_in_render_content(self):
        comment = self.parent_comment_1
        comment.content = "Any long text\n\njust for testing render\n\n\ncontent function"

        result = render_content(comment)

        self.assertIn('<br><br>', result['text_1'])
        self.assertNotIn('<br><br><br>', result['text_1'])
コード例 #4
0
    def test_content_wrapping_with_small_truncate_number(self):
        self.comment.refresh_from_db()
        content_words = self.comment.content.split()
        self.assertEqual(len(content_words), len(self.content.split()))

        result = render_content(self.comment)

        # truncate number is smaller than words in content
        self.assertEqual(result['text_1'], ' '.join(content_words[:5]))
        self.assertEqual(result['text_2'], ' '.join(content_words[5:]))
コード例 #5
0
    def test_multiple_line_breaks(self):
        comment = self.parent_comment_1
        comment.content = "Any long text\n\njust for testing render\n\n\ncontent function"
        comment.save()
        comment.refresh_from_db()

        result = render_content(comment)

        self.assertIn('<br><br>', result['text_1'])
        self.assertNotIn('<br><br><br>', result['text_1'])
コード例 #6
0
    def test_render_content_with_passing_value(self):
        comment = self.parent_comment_1
        content = "Any long text just for testing render content function"
        comment.content = content
        comment.save()
        content_words = comment.content.split()
        self.assertEqual(len(content_words), len(content.split()))

        result = render_content(comment, 5)
        # test urlhash
        self.assertEqual(result['urlhash'], comment.urlhash)
        # truncate number is smaller than content words
        self.assertEqual(result['text_1'], ' '.join(content_words[:5]))
        self.assertEqual(result['text_2'], ' '.join(content_words[5:]))
コード例 #7
0
    def test_render_content(self):
        comment = self.parent_comment_1
        content = "Any long text just for testing render content function"
        comment.content = content
        comment.save()
        content_words = comment.content.split()
        self.assertEqual(len(content_words), len(content.split()))

        result = render_content(comment)
        # test urlhash
        self.assertEqual(result['urlhash'], comment.urlhash)
        # truncate number is bigger than content words
        self.assertEqual(result['text_1'], comment.content)
        self.assertIsNone(result['text_2'])
コード例 #8
0
 def test_urlhash(self):
     result = render_content(self.comment)
     self.assertEqual(result['urlhash'], self.comment.urlhash)