def test_basic_urls(self): self.app.get("/") assert "/foo" == url("/foo") assert "foo/bar" == url(["foo", "bar"]) assert url("/foo", bar=1, baz=2) in \ ["/foo?bar=1&baz=2", "/foo?baz=2&bar=1"] assert url("/foo", dict(bar=1, baz=2)) in \ ["/foo?bar=1&baz=2", "/foo?baz=2&bar=1"] assert url("/foo", dict(bar=1, baz=None)) == "/foo?bar=1"
def url(self, url): """ Returns the absolute path for the given url. """ prefix = self.request_local.environ['toscawidgets.prefix'] return '/' + gearshift.url(prefix+url).lstrip('/')
def url(self, url): """ Returns the absolute path for the given url. """ prefix = self.request_local.environ['toscawidgets.prefix'] return '/' + gearshift.url(prefix + url).lstrip('/')
def test_unicode(self): """url() can handle unicode parameters""" self.app.get("/") assert url('/', x=u'\N{LATIN SMALL LETTER A WITH GRAVE}' u'\N{LATIN SMALL LETTER E WITH GRAVE}' u'\N{LATIN SMALL LETTER I WITH GRAVE}' u'\N{LATIN SMALL LETTER O WITH GRAVE}' u'\N{LATIN SMALL LETTER U WITH GRAVE}') \ == '/?x=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
def __init__(self, errors): """Set up identity errors on the request and get URL from config.""" set_identity_errors(errors) url = get_failure_url(errors) # We need forward URL for both external and internal redirects params = cherrypy.request.params params['forward_url'] = cherrypy.request.path_info if gearshift.config.get('tools.identity.force_external_redirect', False): # We need to use external redirect for https since we are managed # by Apache/nginx or something else that CherryPy won't find. raise cherrypy.HTTPRedirect(gearshift.url(url, params)) else: # use internal redirect which is quicker query_string = urllib.urlencode(params, True) raise cherrypy.InternalRedirect(url, query_string)
def test_url_doesnt_change_tgparams(self): """url() does not change the dict passed as second arg""" params = {'spamm': 'eggs'} assert 'foo' in url('/foo', params, spamm='ham') assert params['spamm'] == 'eggs'
def test_existing_query_string(self): """url() can handle URL with existing query string""" self.app.get("/") test_url = url('/foo', {'first': 1}) assert url(test_url, {'second': 2}) == '/foo?first=1&second=2'
def test_url_kwargs_overwrite_tgparams(self): """Keys in tgparams in call to url() overwrite kw args""" params = {'spamm': 'eggs'} assert 'spamm=ham' in url('/foo', params, spamm='ham')
def test_url_without_request_available(self): #Stopping the server in tearDown ensures that there's no request assert not util.request_available() assert url("/foo") == "/foo"
def test_list(self): """url() can handle list parameters, with unicode too""" self.app.get("/") assert url('/', foo=['bar', u'\N{LATIN SMALL LETTER A WITH GRAVE}' ]) == '/?foo=bar&foo=%C3%A0'
def test_multi_values(self): self.app.get("/") assert url("/foo", bar=[1, 2]) in \ ["/foo?bar=1&bar=2", "/foo?bar=2&bar=1"] assert url("/foo", bar=("asdf", "qwer")) in \ ["/foo?bar=qwer&bar=asdf", "/foo?bar=asdf&bar=qwer"]
def test_list(self): """url() can handle list parameters, with unicode too""" self.app.get("/") assert url('/', foo=['bar', u'\N{LATIN SMALL LETTER A WITH GRAVE}'] ) == '/?foo=bar&foo=%C3%A0'
def index(self): return url("/foo")