1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# -*- coding: utf-8 -*-
import pytest
from rfc3986.uri import URIReference
from rfc3986.normalizers import (
normalize_scheme, normalize_percent_characters, remove_dot_segments
)
def test_normalize_scheme():
assert 'http' == normalize_scheme('htTp')
assert 'http' == normalize_scheme('http')
assert 'http' == normalize_scheme('HTTP')
def test_normalize_percent_characters():
expected = '%3Athis_should_be_lowercase%DF%AB%4C'
assert expected == normalize_percent_characters(
'%3athis_should_be_lowercase%DF%ab%4c')
assert expected == normalize_percent_characters(
'%3Athis_should_be_lowercase%DF%AB%4C')
assert expected == normalize_percent_characters(
'%3Athis_should_be_lowercase%DF%aB%4C')
paths = [
# (Input, expected output)
('/foo/bar/.', '/foo/bar/'),
('/foo/bar/', '/foo/bar/'),
('/foo/bar', '/foo/bar'),
('./foo/bar', 'foo/bar'),
('/./foo/bar', '/foo/bar'),
('/foo%20bar/biz%2Abaz', '/foo%20bar/biz%2Abaz'),
('../foo/bar', 'foo/bar'),
('/../foo/bar', '/foo/bar'),
('a/./b/../b/%63/%7Bfoo%7D', 'a/b/%63/%7Bfoo%7D'),
('//a/./b/../b/%63/%7Bfoo%7D', '//a/b/%63/%7Bfoo%7D'),
('mid/content=5/../6', 'mid/6'),
('/a/b/c/./../../g', '/a/g'),
]
@pytest.fixture(params=paths)
def path_fixture(request):
return request.param
@pytest.fixture(params=paths)
def uris(request):
to_norm, normalized = request.param
return (URIReference(None, None, to_norm, None, None),
URIReference(None, None, normalized, None, None))
def test_remove_dot_segments(path_fixture):
to_normalize, expected = path_fixture
assert expected == remove_dot_segments(to_normalize)
def test_normalized_equality(uris):
assert uris[0] == uris[1]
def test_hostname_normalization():
assert (URIReference(None, 'EXAMPLE.COM', None, None, None) ==
URIReference(None, 'example.com', None, None, None))
def test_authority_normalization():
uri = URIReference(
None, 'user%2aName@EXAMPLE.COM', None, None, None).normalize()
assert uri.authority == 'user%2AName@example.com'
|