@@ -1318,31 +1318,38 @@ def test_multi_url_build() -> None:
13181318 assert str (url ) == 'postgresql://testuser:testpassword@127.0.0.1:5432/database?sslmode=require#test'
13191319
13201320
1321- def test_multi_url_build_encodes_credentials () -> None :
1322- url = MultiHostUrl .build (
1321+ @pytest .mark .parametrize ('url_type' , [Url , MultiHostUrl ])
1322+ def test_url_build_encodes_credentials (url_type : type [Union [Url , MultiHostUrl ]]) -> None :
1323+ url = url_type .build (
13231324 scheme = 'postgresql' ,
13241325 username = 'user name' ,
1325- password = 'p@ss/word?#' ,
1326+ password = 'p@ss/word?#__ ' ,
13261327 host = 'example.com' ,
13271328 port = 5432 ,
13281329 )
1329- assert url == MultiHostUrl ('postgresql://user%20name:p%40ss%2Fword%3F%23@example.com:5432' )
1330- assert str (url ) == 'postgresql://user%20name:p%40ss%2Fword%3F%23@example.com:5432'
1331- assert url .hosts () == [
1332- {'username' : 'user%20name' , 'password' : 'p%40ss%2Fword%3F%23' , 'host' : 'example.com' , 'port' : 5432 }
1333- ]
1330+ assert url == url_type ('postgresql://user%20name:p%40ss%2Fword%3F%23__@example.com:5432' )
1331+ assert str (url ) == 'postgresql://user%20name:p%40ss%2Fword%3F%23__@example.com:5432'
1332+ if url_type is Url :
1333+ assert url .username == 'user%20name'
1334+ assert url .password == 'p%40ss%2Fword%3F%23__'
1335+ else :
1336+ assert url .hosts () == [
1337+ {'username' : 'user%20name' , 'password' : 'p%40ss%2Fword%3F%23__' , 'host' : 'example.com' , 'port' : 5432 }
1338+ ]
13341339
13351340
13361341def test_multi_url_build_hosts_encodes_credentials () -> None :
13371342 hosts = [
1338- {'host' : 'example.com' , 'password' : 'p@ss/word?#' , 'username' : 'user name' , 'port' : 5431 },
1339- {'host' : 'example.org' , 'password' : 'pa%ss ' , 'username' : 'other' , 'port' : 5432 },
1343+ {'host' : 'example.com' , 'password' : 'p@ss/word?#__ ' , 'username' : 'user name' , 'port' : 5431 },
1344+ {'host' : 'example.org' , 'password' : 'p@%ss__ ' , 'username' : 'other' , 'port' : 5432 },
13401345 ]
13411346 url = MultiHostUrl .build (scheme = 'postgresql' , hosts = hosts )
1342- assert str (url ) == 'postgresql://user%20name:p%40ss%2Fword%3F%23@example.com:5431,other:pa%25ss@example.org:5432'
1347+ assert (
1348+ str (url ) == 'postgresql://user%20name:p%40ss%2Fword%3F%23__@example.com:5431,other:p%40%25ss__@example.org:5432'
1349+ )
13431350 assert url .hosts () == [
1344- {'username' : 'user%20name' , 'password' : 'p%40ss%2Fword%3F%23 ' , 'host' : 'example.com' , 'port' : 5431 },
1345- {'username' : 'other' , 'password' : 'pa%25ss ' , 'host' : 'example.org' , 'port' : 5432 },
1351+ {'username' : 'user%20name' , 'password' : 'p%40ss%2Fword%3F%23__ ' , 'host' : 'example.com' , 'port' : 5431 },
1352+ {'username' : 'other' , 'password' : 'p%40%25ss__ ' , 'host' : 'example.org' , 'port' : 5432 },
13461353 ]
13471354
13481355
0 commit comments