def test_no_scheme_user_and_pw(self): url = URL('foo:bar@foohost:9999') self.assertEqual(url.scheme, 'http') self.assertEqual(url.host, 'foohost') self.assertEqual(url.port, 9999) self.assertEqual(url.user, 'foo') self.assertEqual(url.password, 'bar')
def test_authentication(self): url = URL('https://*****:*****@localhost:123') self.assertEqual(url.scheme, 'https') self.assertEqual(url.host, 'localhost') self.assertEqual(url.port, 123) self.assertEqual(url.user, 'foo') self.assertEqual(url.password, 'bar')
def test_attributes(self): url = URL('http://*****:*****@localhost:123/foo') self.assertEqual(url.scheme, 'http') self.assertEqual(url.user, 'user') self.assertEqual(url.password, 'pw') self.assertEqual(url.host, 'localhost') self.assertEqual(url.port, 123) self.assertEqual(url.path, '/foo')
def test_url_scrape(self): from stig.client.utils import URL self.check_filter( TrackerFilter, filter_names=('url-scrape', 'sc'), items=({ 'id': 1, 'url-scrape': URL('http://abc.example.com:1234/foo/scrape') }, { 'id': 2, 'url-scrape': URL('http://abc.example.com:1234/bar/scrape') }, { 'id': 3, 'url-scrape': URL('http://def.example.com:4321/scrape') }), test_cases=(('{name}', (1, 2, 3)), ('!{name}', ()), ('{name}=http://abc.example.com:1234/bar/scrape', (2, )), ('{name}~abc', (1, 2))))
def test_mutability_and_cache(self): url = URL('https://foo.example.com:123/foo') url.port = 321 url.host = 'bar.example.com' url.scheme = 'http' self.assertEqual(str(url), 'http://bar.example.com:321/foo') self.assertEqual(url.domain, 'example.com') url.host = 'foo.bar.com' self.assertEqual(url.domain, 'bar.com') self.assertEqual(str(url), 'http://foo.bar.com:321/foo')
def test_repr(self): url = URL('https://*****:*****@localhost:123/foo/bar/baz') self.assertEqual(repr(url), '<URL https://foo:bar@localhost:123/foo/bar/baz>')
def test_str(self): url = URL('https://*****:*****@localhost:123') self.assertEqual(str(url), 'https://*****:*****@localhost:123') url = URL('localhost') self.assertEqual(str(url), 'http://localhost')
def test_no_scheme_with_port(self): url = URL('foohost:9999') self.assertEqual(url.scheme, 'http') self.assertEqual(url.host, 'foohost') self.assertEqual(url.port, 9999)
def test_empty_string(self): url = URL('') self.assertEqual(url.scheme, None) self.assertEqual(url.host, None) self.assertEqual(url.port, None) self.assertEqual(str(url), '')
def test_no_scheme(self): url = URL('foohost') self.assertEqual(url.scheme, 'http') self.assertEqual(url.host, 'foohost') self.assertEqual(url.port, None)
def test_invalid_port(self): url = URL('foohost:70123') self.assertEqual(url.scheme, 'http') self.assertEqual(url.host, 'foohost') self.assertEqual(url.port, 70123)
def test_authentication_empty_user_and_password(self): url = URL(':@localhost') self.assertEqual(url.user, None) self.assertEqual(url.password, None) self.assertEqual(url.host, 'localhost')
def test_authentication_no_password(self): url = URL('foo@localhost') self.assertEqual(url.user, 'foo') self.assertEqual(url.password, None) self.assertEqual(url.host, 'localhost')
def test_no_scheme(self): url = URL('localhost/foo') self.assertEqual(url.scheme, 'http') self.assertEqual(url.host, 'localhost') self.assertEqual(url.port, None) self.assertEqual(url.path, '/foo')