Debian Codegraph @

tests/test_urn.py

raw
1 """Tests for the urn module."""
2
3 from aiowebdav2.urn import Urn
4
5
6 def test_urn_normalizes_and_quotes_path() -> None:
7 """Test urn normalizes and quotes path."""
8 urn = Urn("test space/./file", directory=False)
9 assert urn.path() == "/test space/file"
10 assert urn.quote() == "/test%20space/file"
11
12
13 def test_urn_parent_and_filename_for_dir() -> None:
14 """Test urn parent and filename for dir."""
15 urn = Urn("/test_dir/test child/", directory=True)
16 assert urn.filename() == "test child/"
17 assert urn.parent() == "/test_dir/"
18
19
20 def test_urn_parent_for_root_child() -> None:
21 """Test urn parent for root child."""
22 urn = Urn("/test_dir/test.txt")
23 assert urn.parent() == "/test_dir/"
24
25
26 def test_urn_is_dir_and_nesting_level() -> None:
27 """Test urn is dir and nesting level."""
28 urn = Urn("/test_dir/test_dir2/", directory=True)
29 assert urn.is_dir()
30 assert urn.nesting_level() == 2
31
32
33 def test_urn_normalize_path_and_compare_path() -> None:
34 """Test urn normalize path and compare path."""
35 normalized = Urn.normalize_path("//test_dir//")
36 assert normalized == "/test_dir"
37 assert Urn.compare_path("/test_dir", "https://example.com/test_dir")
38
39
40 def test_urn_parent_segment_normalization() -> None:
41 """Test urn normalizes parent segment references."""
42 assert Urn("/a/b/../c").path() == "/a/c"
43 assert Urn("/a/b/c/../../d").path() == "/a/d"
44 assert Urn("/parent/..").path() == "/"
45 assert Urn("/a/b/..").path() == "/a/"