@@ -49,6 +49,9 @@ class TestCaseWithCluster(unittest.TestCase):
4949 postgresql.driver *interface* tests.
5050 """
5151 installation = default_installation
52+ @property
53+ def _crt (self ):
54+ return self .params .get ('sslrootcrtfile' ) or None
5255
5356 def __init__ (self , * args , ** kw ):
5457 super ().__init__ (* args , ** kw )
@@ -119,6 +122,7 @@ def initialize_database(self):
119122 c = self .cluster .connection (
120123 user = 'test' ,
121124 database = 'template1' ,
125+ sslrootcrtfile = self ._crt ,
122126 )
123127 with c :
124128 if c .prepare (
@@ -128,13 +132,15 @@ def initialize_database(self):
128132 c .execute ('create database test' )
129133
130134 def connection (self , * args , ** kw ):
131- return self .cluster .connection (* args , user = 'test' , ** kw )
135+ return self .cluster .connection (* args , user = 'test' , ** self . params , ** kw )
132136
133137 def drop_cluster (self ):
134138 if self .cluster .initialized ():
135139 self .cluster .drop ()
136140
137141 def run (self , * args , ** kw ):
142+ self .params = {}
143+
138144 if 'PGINSTALLATION' not in os .environ :
139145 # Expect tests to show skipped.
140146 return super ().run (* args , ** kw )
@@ -174,7 +180,6 @@ class test_connect(TestCaseWithCluster):
174180 ip6 = '::1'
175181 ip4 = '127.0.0.1'
176182 host = 'localhost'
177- params = {}
178183 cluster_path_suffix = '_test_connect'
179184
180185 mk_common_users = """
@@ -228,19 +233,21 @@ def configure_cluster(self):
228233 def initialize_database (self ):
229234 super ().initialize_database ()
230235
231- with self .cluster . connection (user = 'test' ) as db :
236+ with self .connection () as db :
232237 db .execute (self .mk_common_users )
233238 if self .check_crypt_user :
234239 db .execute (self .mk_crypt_user )
235240
236241 @unittest .skipIf (default_installation is None , "no installation provided by environment" )
237242 def test_pg_open_SQL_ASCII (self ):
238- # postgresql.open
239243 host , port = self .cluster .address ()
244+ dbctx = self .params
245+
240246 # test simple locators..
241247 with pg_open (
242248 'pq://' + 'md5:' + 'md5_password@' + host + ':' + str (port ) \
243- + '/test?client_encoding=SQL_ASCII'
249+ + '/test?client_encoding=SQL_ASCII' ,
250+ ** dbctx
244251 ) as db :
245252 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
246253 self .assertEqual (db .settings ['client_encoding' ], 'SQL_ASCII' )
@@ -249,66 +256,78 @@ def test_pg_open_SQL_ASCII(self):
249256 @unittest .skipIf (default_installation is None , "no installation provided by environment" )
250257 def test_pg_open_keywords (self ):
251258 host , port = self .cluster .address ()
252- # straight test, no IRI
259+ dbctx = self .params
260+
261+ # Keywords only, no indicator.
253262 with pg_open (
254263 user = 'md5' ,
255264 password = 'md5_password' ,
256265 host = host ,
257266 port = port ,
258- database = 'test'
267+ database = 'test' ,
268+ ** dbctx ,
259269 ) as db :
260270 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
261- self . assertTrue ( db . closed )
262- # composite test
271+
272+ # Keyword and indicator source.
263273 with pg_open (
264274 "pq://md5:md5_password@" ,
265275 host = host ,
266276 port = port ,
267- database = 'test'
277+ database = 'test' ,
278+ ** dbctx ,
268279 ) as db :
269280 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
270- # override test
281+
282+ # Keyword override.
271283 with pg_open (
272284 "pq://md5:foobar@" ,
273285 password = 'md5_password' ,
274286 host = host ,
275287 port = port ,
276- database = 'test'
288+ database = 'test' ,
289+ ** dbctx ,
277290 ) as db :
278291 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
279- # and, one with some settings
292+
293+ # Settings override.
280294 with pg_open (
281295 "pq://md5:foobar@?search_path=ieeee" ,
282296 password = 'md5_password' ,
283297 host = host ,
284298 port = port ,
285299 database = 'test' ,
286- settings = {'search_path' : 'public' }
300+ settings = {'search_path' : 'public' },
301+ ** dbctx ,
287302 ) as db :
288303 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
289304 self .assertEqual (db .settings ['search_path' ], 'public' )
290305
291306 @unittest .skipIf (default_installation is None , "no installation provided by environment" )
292307 def test_pg_open (self ):
293- # postgresql.open
294308 host , port = self .cluster .address ()
309+ dbctx = self .params
310+
295311 # test simple locators..
296312 with pg_open (
297313 'pq://' + 'md5:' + 'md5_password@' + host + ':' + str (port ) \
298- + '/test'
314+ + '/test' ,
315+ ** dbctx ,
299316 ) as db :
300317 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
301318 self .assertTrue (db .closed )
302319
303320 with pg_open (
304321 'pq://' + 'password:' + 'password_password@' + host + ':' + str (port ) \
305- + '/test'
322+ + '/test' ,
323+ ** dbctx ,
306324 ) as db :
307325 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
308326 self .assertTrue (db .closed )
309327
310328 with pg_open (
311- 'pq://' + 'trusted@' + host + ':' + str (port ) + '/test'
329+ 'pq://' + 'trusted@' + host + ':' + str (port ) + '/test' ,
330+ ** dbctx ,
312331 ) as db :
313332 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
314333 self .assertTrue (db .closed )
@@ -324,7 +343,7 @@ def test_pg_open(self):
324343 os .environ ['PGPORT' ] = str (port )
325344 os .environ ['PGDATABASE' ] = 'test'
326345 # No arguments, the environment provided everything.
327- with pg_open () as db :
346+ with pg_open (** dbctx ) as db :
328347 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
329348 self .assertEqual (db .prepare ('select current_user' ).first (), 'md5' )
330349 self .assertTrue (db .closed )
@@ -354,7 +373,7 @@ def test_pg_open(self):
354373 try :
355374 os .environ ['PGSERVICE' ] = 'myserv'
356375 os .environ ['PGSYSCONFDIR' ] = os .getcwd ()
357- with pg_open () as db :
376+ with pg_open (** dbctx ) as db :
358377 self .assertEqual (db .prepare ('select 1' )(), [(1 ,)])
359378 self .assertEqual (db .prepare ('select current_user' ).first (), 'password' )
360379 self .assertEqual (db .settings ['search_path' ], 'public' )
@@ -505,6 +524,7 @@ def test_password_connect(self):
505524 user = 'password' ,
506525 password = 'password_password' ,
507526 database = 'test' ,
527+ sslrootcrtfile = self ._crt ,
508528 )
509529 with c :
510530 self .assertEqual (c .prepare ('select current_user' ).first (), 'password' )
@@ -524,6 +544,7 @@ def test_trusted_connect(self):
524544 def test_Unix_connect (self ):
525545 if not has_unix_sock :
526546 return
547+
527548 unix_domain_socket = os .path .join (
528549 self .cluster .data_directory ,
529550 '.s.PGSQL.' + self .cluster .settings ['port' ]
0 commit comments