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_iri_update_query(self): iri = IRI(u'http://\N{SNOWMAN}/') q = iri.query q.update({'foo': u'42'}) iri2 = iri.update_query(q) self.assertNotEquals(iri, iri2) self.assertTrue(isinstance(iri2, IRI)) self.assertEquals(repr(iri.query), "MultiDict([])") self.assertEquals(repr(iri2), "IRI(u'http://\u2603/?foo=42')") self.assertEquals(repr(iri2.query), "MultiDict([('foo', u'42')])")
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_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_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)
class TestIRISnowman(cases.IdentifierCase): ri = IRI("http://*****:*****@www.\N{SNOWMAN}:80/path?q=arg#frag") 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", )
class TestIRIIPv6(cases.IdentifierCase): ri = IRI("http://*****:*****@[2a00:1450:4001:c01::67]:80/path?q=arg#frag") expect = dict( scheme="http", auth="u:p", hostname="2a00:1450:4001:c01::67", port="80", path="/path", query=MultiDict([('q', 'arg')]), querystr='q=arg', fragment="frag", netloc="u:p@[2a00:1450:4001:c01::67]:80", )
class TestIRIPileOfPoo(cases.IdentifierCase): ri = IRI("http://*****:*****@www.💩.la:80/path?q=arg#frag") expect = dict( scheme="http", auth="u:p", hostname="www.💩.la", port="80", path="/path", query=MultiDict([('q', 'arg')]), querystr='q=arg', fragment="frag", netloc="u:p@www.💩.la: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_iri_add_port(self): iri = IRI(u'http://\N{SNOWMAN}/') new_iri = iri.update(port=8000) self.assertEquals(iri.netloc + ':8000', new_iri.netloc) self.assertEquals(new_iri.port, '8000') self.assertEquals(iri.port, None)
def test_iri_template(): eq_(IRI(u'http://\u2603/value'), IRI.from_template(u'http://\N{SNOWMAN}/{var}', var='value')) eq_(IRI(u'http://\u2603/'), IRI.from_template(u'http://{domain}/', domain=u"\N{SNOWMAN}"))
def test_iri_from_lenient(self): lenient_iri = IRI.from_lenient(u'http://de.wikipedia.org/wiki/Elf (Begriffskl\xe4rung)') self.assertEquals(repr(lenient_iri), "IRI(u'http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29')")
def test_cannot_join_uri(self): self.assertRaises(TypeError, IRI('http://localhost:8000').join, URI(str('/path/to/file')) )
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_idn_ascii_encoding(self): iri = IRI("http://Bücher.ch/") self.assertEquals(str(iri), "http://xn--bcher-kva.ch/")
def test_configurable_multi_dict_class(self): class CustomMultiDict(MultiDict): pass iri = IRI(u'http://\N{SNOWMAN}/', query_cls=CustomMultiDict) self.assertTrue(isinstance(iri.query, CustomMultiDict))
def test_query_param_breaks_equality_(self): iri = IRI(u'http://\N{CLOUD}/') iri2 = IRI(u'http://\N{CLOUD}/?q=a') self.assertNotEquals(iri, iri2)
def test_non_existent_scheme(self): try: IRI("watwatwat://wat.wat/wat") except Exception as e: assert False, "{0} {1}".format(type(e), e)
def test_nonascii_query_keys(self): IRI(u'http://example.com/?gro\xdf=great')
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)))