def test_cyrillic_path(self): url1 = URL.from_url( u'http://test.ru/тест'.encode('utf-8')) # encoded unicode url2 = URL.from_url(u'http://test.ru/тест') # decoded unicode # should work both without errors self.assertEqual(url1.path, '/%D1%82%D0%B5%D1%81%D1%82') self.assertEqual(url1.path, url2.path)
def test_broken_idna(self): src = u'http://xn--.xn--p1ai/' url = URL.from_url(src.encode('utf-8')) self.assertEqual(url.get_readable(), u'http://xn--.рф/') self.assertEqual(str(url), src) url = URL.from_url(src) self.assertEqual(url.get_readable(), u'http://xn--.рф/')
def test_from_url_idna(self): src = (u'http://xn--80aswg.xn--p1ai' u'/%D1%83%D1%80%D0%BB/' u'?q=%D0%BF%D0%BE%D0%B8%D1%81%D0%BA' u'#%D1%8F%D0%BA%D0%BE%D1%80%D1%8C') url = URL.from_url(src.encode('utf-8')) self.assertEqual(url.get_readable(), u'http://сайт.рф/урл/?q=поиск#якорь') url = URL.from_url(src) self.assertEqual(url.get_readable(), u'http://сайт.рф/урл/?q=поиск#якорь')
def test_copy_url(self): url_orig = URL.from_url(u"http://test.ru/тест?arg=value#anchor") url_copy = copy.copy(url_orig) self.assertEqual(str(url_orig), str(url_copy)) url_deepcopy = copy.deepcopy(url_orig) self.assertEqual(str(url_orig), str(url_deepcopy))
def test_from_url_unicode(self): url = URL.from_url(u'http://сайт.рф/', show_host=False) self.assertEqual(url.schema, 'http') self.assertEqual(url.host, u'сайт.рф') self.assertEqual(url.port, '') self.assertEqual(url.path, '/') self.assertEqual(url.show_host, False)
def test_from_url_path(self): url = URL.from_url('/url?a=1&b=2&b=3') self.assertEqual(url.schema, 'http') self.assertEqual(url.host, '') self.assertEqual(url.port, '') self.assertEqual(url.path, '/url') self.assertEqual(url.query.items(), [('a' ,'1'), ('b', '2'), ('b', '3')])
def test_from_url_unicode(self): url = URL.from_url(u'http://сайт.рф/', show_host=False) self.assertEqual(url.scheme, 'http') self.assertEqual(url.host, u'сайт.рф') self.assertEqual(url.port, '') self.assertEqual(url.path, '/') self.assertEqual(url.show_host, False)
def test_from_url_path(self): url = URL.from_url('/url?a=1&b=2&b=3') self.assertEqual(url.scheme, 'http') self.assertEqual(url.host, '') self.assertEqual(url.port, '') self.assertEqual(url.path, '/url') self.assertEqual(set(url.query.items()), {('a' ,'1'), ('b', '2'), ('b', '3')})
def test_from_url(self): url = URL.from_url('http://example.com/url?a=1&b=2&b=3', show_host=False) self.assertEqual(url.schema, 'http') self.assertEqual(url.host, 'example.com') self.assertEqual(url.port, '') self.assertEqual(url.path, '/url') self.assertEqual(url.query.items(), [('a' ,'1'), ('b', '2'), ('b', '3')]) self.assertEqual(url.show_host, False)
def test_from_url(self): url = URL.from_url('http://example.com/url?a=1&b=2&b=3#anchor', show_host=False) self.assertEqual(url.scheme, 'http') self.assertEqual(url.host, 'example.com') self.assertEqual(url.port, '') self.assertEqual(url.path, '/url') self.assertEqual(url.fragment, 'anchor') self.assertEqual(set(url.query.items()), {('a' ,'1'), ('b', '2'), ('b', '3')}) self.assertEqual(url.show_host, False)
def test_from_url_idna(self): url = URL.from_url('http://xn--80aswg.xn--p1ai/%D1%83%D1%80%D0%BB/?q=%D0%BF%D0%BE%D0%B8%D1%81%D0%BA') self.assertEqual(url.get_readable(), u'http://сайт.рф/урл/?q=поиск')
def test_from_url_broken_unicode(self): url = URL.from_url('/search%E3%81?q=hello%E3%81#hash%E3%81') self.assertEqual(url.get_readable(), u'/search\N{REPLACEMENT CHARACTER}' u'?q=hello\N{REPLACEMENT CHARACTER}' u'#hash\N{REPLACEMENT CHARACTER}')
def test_empty_fragment(self): self.assertEqual(URL.from_url('/').fragment, None) self.assertEqual(URL.from_url('/#').fragment, '') self.assertEqual(URL('/', fragment=None), '/') self.assertEqual(URL('/', fragment='') ,'/#')
def test_parse_cp_1251(self): url_string = u"http://test.com/?query=привет".encode('cp1251') url = URL.from_url(url_string) self.assertEqual(url.host, 'test.com') self.assertEqual(url.query['query'], u'\N{REPLACEMENT CHARACTER}'*6)
def test_from_url_broken_unicode(self): url = URL.from_url('/search?q=hello%E3%81') self.assertEqual(url.get_readable(), u'/search?q=hello�')
def test_cyrillic_path(self): url1 = URL.from_url('http://test.ru/тест') # encoded unicode url2 = URL.from_url(u'http://test.ru/тест') # decoded unicode # should work both without errors self.assertEqual(url1.path, '/%D1%82%D0%B5%D1%81%D1%82') self.assertEqual(url1.path, url2.path)