def goto(self, href, method='get', **args): """ Go to the (potentially relative) link ``href``, using the given method (``'get'`` or ``'post'``) and any extra arguments you want to pass to the :meth:`webtest.app.TestApp.get` or :meth:`webtest.app.TestApp.post` methods. All hostnames and schemes will be ignored. """ scheme, host, path, query, fragment = urlparse.urlsplit(href) # We scheme = host = fragment = '' href = urlparse.urlunsplit((scheme, host, path, query, fragment)) href = urlparse.urljoin(self.request.url, href) method = method.lower() assert method in ('get', 'post'), ( 'Only "get" or "post" are allowed for method (you gave %r)' % method) # encode unicode strings for the outside world if not PY3 and getattr(self, '_use_unicode', False): def to_str(s): if isinstance(s, text_type): return s.encode(self.charset) return s href = to_str(href) if 'params' in args: args['params'] = [ tuple(map(to_str, p)) for p in args['params'] ] if 'upload_files' in args: args['upload_files'] = [ map(to_str, f) for f in args['upload_files'] ] if 'content_type' in args: args['content_type'] = to_str(args['content_type']) if method == 'get': method = self.test_app.get else: method = self.test_app.post return method(href, **args)
def goto(self, href, method='get', **args): """ Go to the (potentially relative) link ``href``, using the given method (``'get'`` or ``'post'``) and any extra arguments you want to pass to the ``app.get()`` or ``app.post()`` methods. All hostnames and schemes will be ignored. """ scheme, host, path, query, fragment = urlparse.urlsplit(href) # We scheme = host = fragment = '' href = urlparse.urlunsplit((scheme, host, path, query, fragment)) href = urlparse.urljoin(self.request.url, href) method = method.lower() assert method in ('get', 'post'), ( 'Only "get" or "post" are allowed for method (you gave %r)' % method) # encode unicode strings for the outside world if not PY3 and getattr(self, '_use_unicode', False): def to_str(s): if isinstance(s, text_type): return s.encode(self.charset) return s href = to_str(href) if 'params' in args: args['params'] = [tuple(map(to_str, p)) \ for p in args['params']] if 'upload_files' in args: args['upload_files'] = [map(to_str, f) \ for f in args['upload_files']] if 'content_type' in args: args['content_type'] = to_str(args['content_type']) if method == 'get': method = self.test_app.get else: method = self.test_app.post return method(href, **args)
def goto(self, href, method="get", **args): """ Go to the (potentially relative) link ``href``, using the given method (``'get'`` or ``'post'``) and any extra arguments you want to pass to the :meth:`webtest.app.TestApp.get` or :meth:`webtest.app.TestApp.post` methods. All hostnames and schemes will be ignored. """ scheme, host, path, query, fragment = urlparse.urlsplit(href) # We scheme = host = fragment = "" href = urlparse.urlunsplit((scheme, host, path, query, fragment)) href = urlparse.urljoin(self.request.url, href) method = method.lower() assert method in ("get", "post"), 'Only "get" or "post" are allowed for method (you gave %r)' % method # encode unicode strings for the outside world if not PY3 and getattr(self, "_use_unicode", False): def to_str(s): if isinstance(s, text_type): return s.encode(self.charset) return s href = to_str(href) if "params" in args: args["params"] = [tuple(map(to_str, p)) for p in args["params"]] if "upload_files" in args: args["upload_files"] = [map(to_str, f) for f in args["upload_files"]] if "content_type" in args: args["content_type"] = to_str(args["content_type"]) if method == "get": method = self.test_app.get else: method = self.test_app.post return method(href, **args)
def goto(self, href, method='get', **args): """ Go to the (potentially relative) link ``href``, using the given method (``'get'`` or ``'post'``) and any extra arguments you want to pass to the :meth:`webtest.app.TestApp.get` or :meth:`webtest.app.TestApp.post` methods. All hostnames and schemes will be ignored. """ scheme, host, path, query, fragment = urlparse.urlsplit(href) # We scheme = host = fragment = '' href = urlparse.urlunsplit((scheme, host, path, query, fragment)) href = urlparse.urljoin(self.request.url, href) method = method.lower() assert method in ('get', 'post'), ( 'Only "get" or "post" are allowed for method (you gave %r)' % method) if method == 'get': method = self.test_app.get else: method = self.test_app.post return method(href, **args)
def _remove_fragment(self, url): scheme, netloc, path, query, fragment = urlparse.urlsplit(url) return urlparse.urlunsplit((scheme, netloc, path, query, ""))