Example #1
0
 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")
Example #2
0
 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")
Example #3
0
 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")
Example #4
0
 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/")
Example #5
0
 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")
Example #6
0
 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/")
Example #7
0
 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/")
Example #8
0
 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")
Example #9
0
 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")
Example #10
0
 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")
Example #11
0
 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")
Example #12
0
 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")
Example #13
0
 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")
Example #14
0
 def test_unicode_in_username(self):
     self.assertEquals(apply_template("http://{q}@example.com",
                                      q=u"Espa\u00F1a"),
                       "http://Espa%C3%[email protected]")
Example #15
0
 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")
Example #16
0
 def test_spaces(self):
     self.assertEquals(
         apply_template("http://example.com/search?q={searchTerms}",
                        searchTerms="Andrew Dalke"),
         "http://example.com/search?q=Andrew+Dalke")
Example #17
0
 def test_single_term(self):
     self.assertEquals(
         apply_template("http://example.com/search?q={searchTerms}",
                        searchTerms="Andrew"),
         "http://example.com/search?q=Andrew")
Example #18
0
 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")
Example #19
0
 def test_unicode_in_username(self):
     self.assertEquals(
         apply_template("http://{q}@example.com", q=u"Espa\u00F1a"),
         "http://Espa%C3%[email protected]")
Example #20
0
 def test_single_term(self):
     self.assertEquals(apply_template("http://example.com/search?q={searchTerms}",
                                      searchTerms="Andrew"),
                       "http://example.com/search?q=Andrew")
Example #21
0
 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/")
Example #22
0
 def test_spaces(self):
     self.assertEquals(apply_template("http://example.com/search?q={searchTerms}",
                                      searchTerms="Andrew Dalke"),
                       "http://example.com/search?q=Andrew+Dalke")