def test_utf8_excerpt(self): """Characters should stay in UTF-8.""" wc = WikiClient() page = Document.objects.get(pk=4) q = u'fa\xe7on' excerpt = wc.excerpt(page.html, q) assert q in excerpt, u'%s not in %s' % (q, excerpt)
def test_unicode_excerpt(self): """Unicode characters in the excerpt should not be a problem.""" wc = WikiClient() page = Document.objects.get(pk=2) try: excerpt = wc.excerpt(page.html, u'\u3068') render('{{ c }}', {'c': excerpt}) except UnicodeDecodeError: self.fail('Raised UnicodeDecodeError.')
def test_clean_excerpt(self): """SearchClient.excerpt() should not allow disallowed HTML through.""" wc = WikiClient() # Index strips HTML qc = QuestionsClient() # Index does not strip HTML input = "test <div>the start of something</div>" output_strip = "<b>test</b> the start of something" output_nostrip = "<b>test</b> <div>the start of " "something</div>" eq_(output_strip, wc.excerpt(input, "test")) eq_(output_nostrip, qc.excerpt(input, "test"))
def test_clean_excerpt(self): """SearchClient.excerpt() should not allow disallowed HTML through.""" wc = WikiClient() # Index strips HTML qc = QuestionsClient() # Index does not strip HTML input = 'test <div>the start of something</div>' output_strip = '<b>test</b> the start of something' output_nostrip = ('<b>test</b> <div>the start of ' 'something</div>') eq_(output_strip, wc.excerpt(input, 'test')) eq_(output_nostrip, qc.excerpt(input, 'test'))
def test_unicode_excerpt(self): """Unicode characters in the excerpt should not be a problem.""" wc = WikiClient() q = 'contribute' results = wc.query(q) eq_(1, len(results)) page = WikiPage.objects.get(pk=results[0]['id']) try: excerpt = wc.excerpt(page.content, q) render('{{ c }}', {'c': excerpt}) except UnicodeDecodeError: self.fail('Raised UnicodeDecodeError.')
def test_none_content_excerpt(self): """SearchClient.excerpt() returns empty string for None type.""" wc = WikiClient() eq_('', wc.excerpt(None, 'test'))
def test_empty_content_excerpt(self): """SearchClient.excerpt() returns empty string for empty content.""" wc = WikiClient() eq_('', wc.excerpt('', 'test'))
def test_clean_excerpt(self): """SearchClient.excerpt() should not allow disallowed HTML through.""" wc = WikiClient() # Index strips HTML input = 'test <div>the start of something</div>' output_strip = '<b>test</b> the start of something' eq_(output_strip, wc.excerpt(input, 'test'))
def test_clean_excerpt(self): """SearchClient.excerpt() should not allow disallowed HTML through.""" wc = WikiClient() eq_('<b>test</b></style>', wc.excerpt('test</style>', 'test'))