summaryrefslogtreecommitdiff
path: root/tests/test_normalizers.py
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2014-06-30 23:17:28 +0000
committer <>2014-10-24 11:03:41 +0000
commit9817ec3e47bca8fba9a7cac56d785e9d644f7473 (patch)
tree2eddc46197f66e1629dcdf01bf0cb543c729920c /tests/test_normalizers.py
downloadpython-rfc3986-9817ec3e47bca8fba9a7cac56d785e9d644f7473.tar.gz
Imported from /home/lorry/working-area/delta_python-packages_python-rfc3986/rfc3986-0.2.0.tar.gz.HEADrfc3986-0.2.0master
Diffstat (limited to 'tests/test_normalizers.py')
-rw-r--r--tests/test_normalizers.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/test_normalizers.py b/tests/test_normalizers.py
new file mode 100644
index 0000000..ddcb97b
--- /dev/null
+++ b/tests/test_normalizers.py
@@ -0,0 +1,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'