def test_hashability(self): iri1 = IRI(u'http://\N{CLOUD}/') iri2 = IRI(u'http://\N{CLOUD}/') self.assertEquals(hash(iri1), hash(iri2)) uri1 = URI(iri1) uri2 = URI('http://xn--l3h/') self.assertEquals(hash(uri1), hash(uri2)) self.assertNotEquals(hash(iri1), hash(uri1))
def test_ne(self): iri1 = IRI(u'http://\N{CLOUD}/') iri2 = IRI(u'http://\N{CLOUD}/') self.assertFalse(iri1 != iri2) uri1 = URI(iri1) uri2 = URI('http://xn--l3h/') self.assertFalse(uri1 != uri2) self.assertTrue(iri1 != uri1)
def test_eq(self): iri1 = IRI(u'http://\N{CLOUD}/') iri2 = IRI(u'http://\N{CLOUD}/') self.assertEquals(iri1, iri2) uri1 = URI(iri1) uri2 = URI('http://xn--l3h/') self.assertEquals(uri1, uri2) self.assertNotEquals(iri1, uri1)
def test_convert_pile_of_poo(self): raise SkipTest("Not Implemented") uri = URI("http://*****:*****@www.xn--ls8h.la:80/path?q=arg#frag".encode('utf-8')) try: IRI(uri) except Exception as e: assert False, "{0} {1}".format(type(e), e)
def test_convert_pile_of_poo(self): raise SkipTest("Not Implemented") iri = IRI(u"http://*****:*****@www.💩.la:80/path?q=arg#frag") try: URI(iri) except Exception as e: assert False, "{0} {1}".format(type(e), e)
def test_uri_from_lenient(self): lenient_uri = URI.from_lenient( u'http://de.wikipedia.org/wiki/Elf (Begriffskl\xe4rung)'.encode( 'utf-8')) self.assertEquals( repr(lenient_uri), "URI('http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29')" )
class TestURIJoin(cases.JoinAndUpdateCase): RI = lambda self, s: URI(self._literal_wrapper(s), encoding='utf-8') def _literal_wrapper(self, lit): return lit.encode('utf-8') def test_cannot_join_uri(self): self.assertRaises(TypeError, self.RI('http://localhost:8000').join, IRI(u'/path/to/file'))
class TestURIPileOfPoo(cases.IdentifierCase): ri = URI("http://*****:*****@www.xn--ls8h.la:80/path?q=arg#frag") expect = dict( scheme="http", auth="u:p", hostname="www.xn--ls8h.la", port="80", path="/path", query=MultiDict([('q', 'arg')]), querystr='q=arg', fragment="frag", netloc="u:[email protected]:80", )
class TestURISnowman(cases.IdentifierCase): ri = URI("http://*****:*****@www.%s:80/path?q=arg#frag" % u"\N{SNOWMAN}".encode('idna')) expect = dict( scheme="http", auth="u:p", hostname="www.xn--n3h", port="80", path="/path", query=MultiDict([('q', 'arg')]), querystr='q=arg', fragment="frag", netloc="u:[email protected]:80", )
class TestURIConvertedSnowman(cases.IdentifierCase): iri = IRI(u"http://*****:*****@www.\N{SNOWMAN}:80/path?q=arg#frag") ri = URI(iri) expect = dict( scheme="http", auth="u:p", hostname="www.xn--n3h", port="80", path="/path", query=MultiDict([('q', 'arg')]), querystr='q=arg', fragment="frag", netloc="u:[email protected]:80", )
class TestIRIConvertedSnowman(cases.IdentifierCase): uri = URI(("http://*****:*****@www.%s:80/path?q=arg#frag" % u"\N{SNOWMAN}".encode('idna')).encode('utf-8')) ri = IRI(uri) expect = dict( scheme="http", auth="u:p", hostname="www.\u2603", port="80", path="/path", query=MultiDict([('q', 'arg')]), querystr='q=arg', fragment="frag", netloc="u:p@www.\u2603:80", )
def test_uri_from_lenient(self): lenient_uri = URI.from_lenient(u'http://de.wikipedia.org/wiki/Elf (Begriffskl\xe4rung)'.encode('utf-8')) self.assertEquals(repr(lenient_uri), "URI('http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29')")
def test_idn_ascii_encoding(self): uri = URI(u"http://Bücher.ch/".encode('utf-8')) self.assertEquals(str(uri), "http://xn--bcher-kva.ch/")
def setUp(self): self.uri = URI("http://example.com?foo=bar")
def test_non_existent_scheme(self): try: URI("watwatwat://wat.wat/wat") except Exception as e: assert False, "{0} {1}".format(type(e), e)
def test_uri_input(self): iri = TestIRISnowman.ri uri = URI(iri) self.assertEquals(str(iri), str(IRI(uri))) self.assertEquals(unicode(iri), unicode(IRI(uri)))
def test_cannot_join_uri(self): self.assertRaises(TypeError, IRI('http://localhost:8000').join, URI(str('/path/to/file')) )
def test_iri_input(self): uri = TestURISnowman.ri iri = IRI(uri) self.assertEquals(str(uri), str(URI(iri))) self.assertEquals(unicode(uri), unicode(URI(iri)))
def test_uri_template(): eq_(URI("http://example.com/value"), URI.from_template("http://example.com/{var}", var="value"))