Beispiel #1
0
    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')
Beispiel #2
0
    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
Beispiel #3
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'])
Beispiel #4
0
    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/') == ''
Beispiel #5
0
    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'
Beispiel #6
0
    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'
Beispiel #7
0
    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') == '/'
Beispiel #8
0
    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
Beispiel #9
0
    def test_protocol(self):
        test = lambda a: TestImpl.protocol(Link(a))

        assert test('http://www.example.org/') == 'http'
Beispiel #10
0
    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
Beispiel #11
0
    def test_fragment(self):
        test = lambda a: TestImpl.fragment(Link(a))

        assert test('http://www.example.org/path/#fragment') == 'fragment'