mirror of
https://github.com/searxng/searxng
synced 2024-01-01 18:24:07 +00:00
[enh] test utils.prettify_url
This commit is contained in:
parent
da13c3b5f9
commit
7580852bda
@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
import mock
|
import mock
|
||||||
from searx.testing import SearxTestCase
|
from searx.testing import SearxTestCase
|
||||||
from searx import utils
|
from searx import utils
|
||||||
@ -51,6 +52,15 @@ class TestUtils(SearxTestCase):
|
|||||||
self.assertIsNotNone(utils.html_to_text(html))
|
self.assertIsNotNone(utils.html_to_text(html))
|
||||||
self.assertEqual(utils.html_to_text(html), "Test text")
|
self.assertEqual(utils.html_to_text(html), "Test text")
|
||||||
|
|
||||||
|
def test_prettify_url(self):
|
||||||
|
data = (('https://searx.me/', 'https://searx.me/'),
|
||||||
|
(u'https://searx.me/ű', u'https://searx.me/ű'),
|
||||||
|
('https://searx.me/' + (100 * 'a'), 'https://searx.me/[...]aaaaaaaaaaaaaaaaa'),
|
||||||
|
(u'https://searx.me/' + (100 * u'ű'), u'https://searx.me/[...]űűűűűűűűűűűűűűűűű'))
|
||||||
|
|
||||||
|
for test_url, expected in data:
|
||||||
|
self.assertEqual(utils.prettify_url(test_url, max_length=32), expected)
|
||||||
|
|
||||||
|
|
||||||
class TestHTMLTextExtractor(SearxTestCase):
|
class TestHTMLTextExtractor(SearxTestCase):
|
||||||
|
|
||||||
|
@ -222,9 +222,10 @@ def dict_subset(d, properties):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def prettify_url(url):
|
def prettify_url(url, max_length=74):
|
||||||
if len(url) > 74:
|
if len(url) > max_length:
|
||||||
return u'{0}[...]{1}'.format(url[:35], url[-35:])
|
chunk_len = max_length / 2 + 1
|
||||||
|
return u'{0}[...]{1}'.format(url[:chunk_len], url[-chunk_len:])
|
||||||
else:
|
else:
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user