def _parse_url(self, url): """Create a url from test data. If provided with a full URL, just return that. If SSL is requested set the scheme appropriately. Scheme and netloc are saved for later use in comparisons. """ query_params = self.test_data['query_parameters'] ssl = self.test_data['ssl'] parsed_url = urlparse.urlsplit(url) if not parsed_url.scheme: full_url = utils.create_url(url, self.host, port=self.port, prefix=self.prefix, ssl=ssl) # parse again to set updated netloc and scheme parsed_url = urlparse.urlsplit(full_url) self.scheme = parsed_url.scheme self.netloc = parsed_url.netloc if query_params: query_string = self._update_query_params(parsed_url.query, query_params) else: query_string = parsed_url.query return urlparse.urlunsplit((parsed_url.scheme, parsed_url.netloc, parsed_url.path, query_string, ''))
def test_create_url_ssl_on_80(self): url = utils.create_url('/foo/bar', 'test.host.com', ssl=True, port=80) self.assertEqual('https://test.host.com:80/foo/bar', url)
def test_create_url_not_ssl_on_443(self): url = utils.create_url('/foo/bar', 'test.host.com', ssl=False, port=443) self.assertEqual('http://test.host.com:443/foo/bar', url)
def test_create_url_port(self): url = utils.create_url('/foo/bar', 'test.host.com', port=8000) self.assertEqual('http://test.host.com:8000/foo/bar', url)
def test_create_url_prefix(self): url = utils.create_url('/foo/bar', 'test.host.com', prefix='/zoom') self.assertEqual('http://test.host.com/zoom/foo/bar', url)
def test_create_url_ssl(self): url = utils.create_url('/foo/bar', 'test.host.com', ssl=True) self.assertEqual('https://test.host.com/foo/bar', url)
def test_create_url_ipv6_ssl_weird_port(self): url = utils.create_url('/foo/bar?x=1&y=2', '::1', ssl=True, port=80) self.assertEqual('https://[::1]:80/foo/bar?x=1&y=2', url)
def test_create_url_ipv6_full(self): url = utils.create_url('/foo/bar?x=1&y=2', '2607:f8b0:4000:801::200e', port=8080) self.assertEqual( 'http://[2607:f8b0:4000:801::200e]:8080/foo/bar?x=1&y=2', url)
def test_create_url_ipv6_ssl(self): url = utils.create_url('/foo/bar?x=1&y=2', '::1', ssl=True) self.assertEqual('https://[::1]/foo/bar?x=1&y=2', url)
def test_create_url_no_double_colon(self): url = utils.create_url( '/foo', 'FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', port=999) self.assertEqual( 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:999/foo', url)
def test_create_url_ipv6_already_bracket(self): url = utils.create_url( '/foo/bar?x=1&y=2', '[2607:f8b0:4000:801::200e]', port=999) self.assertEqual( 'http://[2607:f8b0:4000:801::200e]:999/foo/bar?x=1&y=2', url)
def test_create_url_preserve_query(self): url = utils.create_url('/foo/bar?x=1&y=2', 'test.host.com', ssl=True, port=80) self.assertEqual('https://test.host.com:80/foo/bar?x=1&y=2', url)
def test_create_url_simple(self): url = utils.create_url('/foo/bar', 'test.host.com') self.assertEqual('http://test.host.com/foo/bar', url)