def test_down(self): test = lambda a,b: TestImpl.down(Link(a, Link(b))) assert not test('http://example.org/bar', 'http://example.org/foo/') assert not test('http://example.org/bar', 'http://example.org/foo') assert test('http://example.org/foo/bar', 'http://example.org/foo') # [regression] assert not test('http://example.org/foo/bar', 'http://example.de/foo')
def test_path_distance(self): test = lambda a,b: TestImpl.path_distance( Link('http://example.org%s' % a, Link('http://example.org%s' % b))) assert test('/foo', '') == False assert test('/foo', '/bar') == False assert test('/foo', '/foobar') == False assert test('/foo', '/foo') == 0 assert test('/foo', '/foo/bar') == -1 assert test('/foo/', '/foo/bar') == 0 assert test('/foo/bar', '/foo') == 1 assert test('/foo/bar', '/foo/') == 0
def test_size(self): test = lambda **kw: TestImpl.size( fake_resolve_link( Link('http://example.org'), no_defaults=True, **kw), NoneDict()) # Prefer content-length header assert test(headers={'content-length': 10}, content='123') == 10 # If no header, use actual content length assert test(headers={}, content='123') == 3 # Do not stumble on invalid headers assert test(headers={'content-length': 'foo'}, content='123') == 3 # raise special error for redirecting requests raises( Redirect, test, headers={'content-length': 'foo'}, redirects=['http://foo'])
def test_querystring(self): test = lambda a: TestImpl.querystring(Link(a)) assert test('http://www.example.org/path/?a=1&b=2') == 'a=1&b=2' assert test('http://www.example.org/path/') == ''
def test_extension(self): test = lambda a: TestImpl.extension(Link(a)) assert test('http://www.example.org/path/') == '' assert test('http://www.example.org/path') == '' assert test('http://www.example.org/index.html') == 'html'
def test_filename(self): test = lambda a: TestImpl.filename(Link(a)) assert test('http://www.example.org/path/') == '' assert test('http://www.example.org/path') == 'path' assert test('http://www.example.org/path/index.html') == 'index.html'
def test_path(self): test = lambda a: TestImpl.path(Link(a)) assert test('http://www.example.org/path/') == '/path/' assert test('http://www.example.org/') == '/' assert test('http://www.example.org') == '/'
def test_port(self): test = lambda a: TestImpl.port(Link(a)) assert test('http://www.example.org/') == 80 assert test('http://www.example.org:8080') == 8080
def test_protocol(self): test = lambda a: TestImpl.protocol(Link(a)) assert test('http://www.example.org/') == 'http'
def test_path_level(self): test = lambda a: TestImpl.path_level(Link(a)) assert test('http://example.org/') == 0 assert test('http://example.org/foo') == 0 assert test('http://example.org/foo/') == 1
def test_fragment(self): test = lambda a: TestImpl.fragment(Link(a)) assert test('http://www.example.org/path/#fragment') == 'fragment'