10
10
from ..conftest import Err , PyAndJson
11
11
12
12
13
- def test_url_ok (py_and_json : PyAndJson ):
14
- v = py_and_json (core_schema .url_schema ())
15
- url = v .validate_test ('https://example.com/foo/bar?baz=qux#quux' )
13
+ def assert_example_url (url : Url ):
14
+ # example URL in question 'https://example.com/foo/bar?baz=qux#quux'
16
15
17
16
assert isinstance (url , Url )
18
17
assert str (url ) == 'https://example.com/foo/bar?baz=qux#quux'
@@ -30,23 +29,51 @@ def test_url_ok(py_and_json: PyAndJson):
30
29
assert url .port == 443
31
30
32
31
32
+ def test_url_ok (py_and_json : PyAndJson ):
33
+ v = py_and_json (core_schema .url_schema ())
34
+ url = v .validate_test ('https://example.com/foo/bar?baz=qux#quux' )
35
+
36
+ assert_example_url (url )
37
+
38
+
33
39
def test_url_from_constructor_ok ():
34
40
url = Url ('https://example.com/foo/bar?baz=qux#quux' )
35
41
36
- assert isinstance (url , Url )
37
- assert str (url ) == 'https://example.com/foo/bar?baz=qux#quux'
38
- assert repr (url ) == "Url('https://example.com/foo/bar?baz=qux#quux')"
39
- assert url .unicode_string () == 'https://example.com/foo/bar?baz=qux#quux'
40
- assert url .scheme == 'https'
41
- assert url .host == 'example.com'
42
- assert url .unicode_host () == 'example.com'
43
- assert url .path == '/foo/bar'
44
- assert url .query == 'baz=qux'
45
- assert url .query_params () == [('baz' , 'qux' )]
46
- assert url .fragment == 'quux'
47
- assert url .username is None
48
- assert url .password is None
49
- assert url .port == 443
42
+ assert_example_url (url )
43
+
44
+
45
+ def test_url_from_build_ok ():
46
+ # 1) no host trailing slash/no path leading slash in the input
47
+ url = Url .build (scheme = 'https' , host = 'example.com' , path = 'foo/bar' , query = 'baz=qux' , fragment = 'quux' )
48
+ assert_example_url (url )
49
+
50
+ # 2) no host trailing slash/with path leading slash in the input
51
+ url = Url .build (scheme = 'https' , host = 'example.com' , path = '/foo/bar' , query = 'baz=qux' , fragment = 'quux' )
52
+ assert_example_url (url )
53
+
54
+ # 3) with host trailing slash/no path leading slash in the input
55
+ url = Url .build (scheme = 'https' , host = 'example.com/' , path = 'foo/bar' , query = 'baz=qux' , fragment = 'quux' )
56
+ assert_example_url (url )
57
+
58
+ # 4) with host trailing slash/with path leading slash in the input
59
+ url = Url .build (scheme = 'https' , host = 'example.com/' , path = '/foo/bar' , query = 'baz=qux' , fragment = 'quux' )
60
+ assert_example_url (url )
61
+
62
+ # 5) query no leading question mark
63
+ url = Url .build (scheme = 'https' , host = 'example.com' , path = 'foo/bar' , query = 'baz=qux' , fragment = 'quux' )
64
+ assert_example_url (url )
65
+
66
+ # 6) query with leading question mark
67
+ url = Url .build (scheme = 'https' , host = 'example.com' , path = 'foo/bar' , query = '?baz=qux' , fragment = 'quux' )
68
+ assert_example_url (url )
69
+
70
+ # 7) fragment no leading hash
71
+ url = Url .build (scheme = 'https' , host = 'example.com' , path = 'foo/bar' , query = 'baz=qux' , fragment = 'quux' )
72
+ assert_example_url (url )
73
+
74
+ # 8) fragment with leading hash
75
+ url = Url .build (scheme = 'https' , host = 'example.com' , path = 'foo/bar' , query = 'baz=qux' , fragment = '#quux' )
76
+ assert_example_url (url )
50
77
51
78
52
79
@pytest .fixture (scope = 'module' , name = 'url_validator' )
0 commit comments