def test_optional(self): self.assertEquals(apply_template("http://example.com/{arg?}"), "http://example.com/") self.assertEquals(apply_template("http://example.com/{arg?}{arg?}"), "http://example.com/") self.assertEquals(apply_template("http://example.com/{arg?}{arg?}", arg="X"), "http://example.com/XX")
def test_unicode_in_path(self): # I double checked the encoding with Safari. Seems to be right self.assertEquals(apply_template("http://google.com/search?q={q}", q=u"Espa\u00F1a"), "http://google.com/search?q=Espa%C3%B1a") self.assertEquals(apply_template(u"http://google.com/search?q={q}", q=u"Espa\u00F1a"), "http://google.com/search?q=Espa%C3%B1a")
def test_optional(self): self.assertEquals(apply_template("http://example.com/{arg?}"), "http://example.com/") self.assertEquals(apply_template("http://example.com/{arg?}{arg?}"), "http://example.com/") self.assertEquals( apply_template("http://example.com/{arg?}{arg?}", arg="X"), "http://example.com/XX")
def test_unicode_in_host_part(self): # I double checked the encoding with Safari. Seems to be right self.assertEquals( apply_template(u"https://{host}.Espa\u00F1a/", host=u"a\u00F1o"), "https://xn--ao-zja.xn--espaa-rta/") self.assertEquals( apply_template(u"http://{host}.\u00F1.name/", host=u"Espa\u00F1a"), "http://xn--espaa-rta.xn--ida.name/")
def test_unicode_in_path(self): # I double checked the encoding with Safari. Seems to be right self.assertEquals( apply_template("http://google.com/search?q={q}", q=u"Espa\u00F1a"), "http://google.com/search?q=Espa%C3%B1a") self.assertEquals( apply_template(u"http://google.com/search?q={q}", q=u"Espa\u00F1a"), "http://google.com/search?q=Espa%C3%B1a")
def test_unicode_in_host(self): # OpenSearch template does not allow this. I do. self.assertEquals(apply_template("https://{host}.name/", host=u"Espa\u00F1a"), "https://xn--espaa-rta.name/") # I also allow Unicode in the host name (but only there!) self.assertEquals(apply_template(u"https://{host}.name/", host=u"Espa\u00F1a"), "https://xn--espaa-rta.name/") self.assertEquals(apply_template(u"https://{host}.a\u00F1o/", host=u"Espa\u00F1a"), "https://xn--espaa-rta.xn--ao-zja/")
def test_unicode_in_host(self): # OpenSearch template does not allow this. I do. self.assertEquals( apply_template("https://{host}.name/", host=u"Espa\u00F1a"), "https://xn--espaa-rta.name/") # I also allow Unicode in the host name (but only there!) self.assertEquals( apply_template(u"https://{host}.name/", host=u"Espa\u00F1a"), "https://xn--espaa-rta.name/") self.assertEquals( apply_template(u"https://{host}.a\u00F1o/", host=u"Espa\u00F1a"), "https://xn--espaa-rta.xn--ao-zja/")
def test_many(self): T = "{scheme}://{host}:{port}/{path}?q={arg}#{hash}" self.assertEquals(apply_template(T, scheme="gopher", host="hole", port="70", path="somewhere/else", arg="spam & eggs", hash="browns"), "gopher://hole:70/somewhere%2Felse?q=spam+%26+eggs#browns")
def test_many(self): T = "{scheme}://{host}:{port}/{path}?q={arg}#{hash}" self.assertEquals( apply_template(T, scheme="gopher", host="hole", port="70", path="somewhere/else", arg="spam & eggs", hash="browns"), "gopher://hole:70/somewhere%2Felse?q=spam+%26+eggs#browns")
def test_using_prefix(self): for uri in ("{spam:x}://dalke:[email protected]/something", "HTTP://{spam:x}:[email protected]/something", "HTTP://{spam:x}:[email protected]/something", "HTTP://*****:*****@example.com/something", "HTTP://*****:*****@{spam:x}.com/something", "HTTP://*****:*****@example.com/{spam:x}"): err = self.raisesTypeError(apply_template, uri) assert err.startswith("Template prefix not supported in Akara (in '"), err # While this should work just fine t = apply_template(uri.replace("spam:", ""), x="123")
def test_using_prefix(self): for uri in ("{spam:x}://dalke:[email protected]/something", "HTTP://{spam:x}:[email protected]/something", "HTTP://{spam:x}:[email protected]/something", "HTTP://*****:*****@example.com/something", "HTTP://*****:*****@{spam:x}.com/something", "HTTP://*****:*****@example.com/{spam:x}"): err = self.raisesTypeError(apply_template, uri) assert err.startswith( "Template prefix not supported in Akara (in '"), err # While this should work just fine t = apply_template(uri.replace("spam:", ""), x="123")
def test_port(self): self.assertEquals(apply_template("http://localhost:8765/"), "http://localhost:8765/") self.assertEquals(apply_template("http://localhost:{port}/", port=8080), "http://localhost:8080/") self.assertEquals(apply_template("http://localhost:{port}/", port="8080"), "http://localhost:8080/") self.assertEquals(apply_template("http://localhost:{port}/abc", port=""), "http://localhost/abc") self.assertEquals(apply_template("http://localhost:{port?}/?q"), "http://localhost/?q") self.assertEquals(apply_template("http://localhost:{port?}/?q", port="123"), "http://localhost:123/?q")
def test_port(self): self.assertEquals(apply_template("http://localhost:8765/"), "http://localhost:8765/") self.assertEquals( apply_template("http://localhost:{port}/", port=8080), "http://localhost:8080/") self.assertEquals( apply_template("http://localhost:{port}/", port="8080"), "http://localhost:8080/") self.assertEquals( apply_template("http://localhost:{port}/abc", port=""), "http://localhost/abc") self.assertEquals(apply_template("http://localhost:{port?}/?q"), "http://localhost/?q") self.assertEquals( apply_template("http://localhost:{port?}/?q", port="123"), "http://localhost:123/?q")
def test_unicode_in_username(self): self.assertEquals(apply_template("http://{q}@example.com", q=u"Espa\u00F1a"), "http://Espa%C3%[email protected]")
def test_no_expansion(self): self.assertEquals(apply_template("http://example.com/osd.xml"), "http://example.com/osd.xml") self.assertEquals(apply_template(u"http://example.com/osd.xml"), "http://example.com/osd.xml")
def test_spaces(self): self.assertEquals( apply_template("http://example.com/search?q={searchTerms}", searchTerms="Andrew Dalke"), "http://example.com/search?q=Andrew+Dalke")
def test_single_term(self): self.assertEquals( apply_template("http://example.com/search?q={searchTerms}", searchTerms="Andrew"), "http://example.com/search?q=Andrew")
def test_unicode_in_username(self): self.assertEquals( apply_template("http://{q}@example.com", q=u"Espa\u00F1a"), "http://Espa%C3%[email protected]")
def test_single_term(self): self.assertEquals(apply_template("http://example.com/search?q={searchTerms}", searchTerms="Andrew"), "http://example.com/search?q=Andrew")
def test_unicode_in_host_part(self): # I double checked the encoding with Safari. Seems to be right self.assertEquals(apply_template(u"https://{host}.Espa\u00F1a/", host=u"a\u00F1o"), "https://xn--ao-zja.xn--espaa-rta/") self.assertEquals(apply_template(u"http://{host}.\u00F1.name/", host=u"Espa\u00F1a"), "http://xn--espaa-rta.xn--ida.name/")
def test_spaces(self): self.assertEquals(apply_template("http://example.com/search?q={searchTerms}", searchTerms="Andrew Dalke"), "http://example.com/search?q=Andrew+Dalke")