@@ -1233,33 +1233,27 @@ def test_multi_url_build() -> None:
1233
1233
assert str (
url )
== 'postgresql://testuser:[email protected] :5432/database?sslmode=require#test'
1234
1234
1235
1235
1236
- def test_multi_url_build_host_and_hosts_set () -> None :
1236
+ @pytest .mark .parametrize ('field' , ['host' , 'password' , 'user' , 'port' ])
1237
+ def test_multi_url_build_hosts_set_with_single_value (field ) -> None :
1238
+ """Hosts can't be provided with any single url values."""
1237
1239
hosts = [
1238
- {
1239
- 'host' : '127.0.0.1:5432' ,
1240
- 'password' : 'testpassword' ,
1241
- 'username' : 'testuser' ,
1242
- 'port' : '5432'
1243
- },
1244
- {
1245
- 'host' : '127.0.0.1:5432' ,
1246
- 'password' : 'testpassword' ,
1247
- 'username' : 'testuser' ,
1248
- 'port' : '5432'
1249
- },
1240
+ {'host' : '127.0.0.1:5432' , 'password' : 'testpassword' , 'username' : 'testuser' , 'port' : '5432' },
1241
+ {'host' : '127.0.0.1:5432' , 'password' : 'testpassword' , 'username' : 'testuser' , 'port' : '5432' },
1250
1242
]
1243
+ kwargs = dict (scheme = 'postgresql' , hosts = hosts , path = 'database' , query = 'sslmode=require' , fragment = 'test' )
1244
+ kwargs [field ] = 'test'
1251
1245
with pytest .raises (ValueError ):
1252
- MultiHostUrl .build (
1253
- scheme = 'postgresql' ,
1254
- user = 'testuser' ,
1255
- password = 'testpassword' ,
1256
- host = '127.0.0.1' ,
1257
- hosts = hosts ,
1258
- port = ' 5432',
1259
- path = 'database' ,
1260
- query = 'sslmode=require' ,
1261
- fragment = 'test' ,
1262
- )
1246
+ MultiHostUrl .build (** kwargs )
1247
+
1248
+
1249
+ @ pytest . mark . parametrize ( 'field' , [ 'host' , ' password' , 'username' , 'port' ])
1250
+ def test_multi_url_build_hosts_invalid_host ( field ) -> None :
1251
+ """Hosts can't be provided with any single url values."""
1252
+ host = { 'host' : '127.0.0.1:5432' , 'password' : 'testpassword' , 'username' : 'testuser' , ' port' : ' 5432'}
1253
+ del host [ field ]
1254
+ with pytest . raises ( ValueError ):
1255
+ MultiHostUrl . build ( scheme = 'postgresql' , hosts = [ host ], path = 'database' , query = 'sslmode=require' , fragment = 'test' )
1256
+
1263
1257
1264
1258
def test_multi_url_build_neither_host_and_hosts_set () -> None :
1265
1259
with pytest .raises (ValueError ):
@@ -1273,6 +1267,7 @@ def test_multi_url_build_neither_host_and_hosts_set() -> None:
1273
1267
fragment = 'test' ,
1274
1268
)
1275
1269
1270
+
1276
1271
def test_url_build () -> None :
1277
1272
url = Url .build (
1278
1273
scheme = 'postgresql' ,
0 commit comments