@@ -51,7 +51,7 @@ def __init__(self, *args, **kw):
5151 super ().__init__ (* args , ** kw )
5252 self .installation = installation .default ()
5353 self .cluster_path = \
54- 'py_unittest_pg_cluster_ ' \
54+ 'pypg_test_ ' \
5555 + str (os .getpid ()) + getattr (self , 'cluster_path_suffix' , '' )
5656
5757 if self .installation is None :
@@ -68,6 +68,8 @@ def __init__(self, *args, **kw):
6868 if self .cluster .initialized ():
6969 self .cluster .drop ()
7070
71+ self .disable_replication = self .installation .version_info [:2 ] > (9 , 6 )
72+
7173 def configure_cluster (self ):
7274 self .cluster_port = find_available_port ()
7375 if self .cluster_port is None :
@@ -79,6 +81,7 @@ def configure_cluster(self):
7981 listen_addresses = '127.0.0.1'
8082 if has_ipv6 :
8183 listen_addresses += ',::1'
84+
8285 self .cluster .settings .update (dict (
8386 port = str (self .cluster_port ),
8487 max_connections = '6' ,
@@ -88,6 +91,11 @@ def configure_cluster(self):
8891 log_min_messages = 'FATAL' ,
8992 ))
9093
94+ if self .disable_replication :
95+ self .cluster .settings .update ({
96+ 'max_wal_senders' : '0' ,
97+ })
98+
9199 if self .cluster .installation .version_info [:2 ] < (9 , 3 ):
92100 self .cluster .settings .update (dict (
93101 unix_socket_directory = self .cluster .data_directory ,
@@ -157,30 +165,43 @@ class test_connect(TestCaseWithCluster):
157165 params = {}
158166 cluster_path_suffix = '_test_connect'
159167
168+ mk_common_users = """
169+ CREATE USER md5 WITH ENCRYPTED PASSWORD 'md5_password';
170+ CREATE USER password WITH ENCRYPTED PASSWORD 'password_password';
171+ CREATE USER trusted;
172+ """
173+
174+ mk_crypt_user = """
175+ -- crypt doesn't work with encrypted passwords:
176+ -- http://www.postgresql.org/docs/8.2/interactive/auth-methods.html#AUTH-PASSWORD
177+ CREATE USER crypt WITH UNENCRYPTED PASSWORD 'crypt_password';
178+ """
179+
160180 def __init__ (self , * args , ** kw ):
161181 super ().__init__ (* args ,** kw )
162182 # 8.4 nixed this.
163- self .do_crypt = self .cluster .installation .version_info < (8 ,4 )
183+ vi = self .cluster .installation .version_info
184+ self .check_crypt_user = (vi < (8 ,4 ))
164185
165186 def configure_cluster (self ):
166187 super ().configure_cluster ()
167- self .cluster .settings .update ({
168- 'log_min_messages' : 'log' ,
169- })
188+ self .cluster .settings ['log_min_messages' ] = 'log'
170189
171190 # Configure the hba file with the supported methods.
172191 with open (self .cluster .hba_file , 'w' ) as hba :
173192 hosts = ['0.0.0.0/0' ,]
174193 if has_ipv6 :
175194 hosts .append ('0::0/0' )
176- methods = ['md5' , 'password' ] + (['crypt' ] if self .do_crypt else [])
195+
196+ methods = ['md5' , 'password' ] + (['crypt' ] if self .check_crypt_user else [])
177197 for h in hosts :
178198 for m in methods :
179199 # user and method are the same name.
180200 hba .writelines (['host test {m} {h} {m}\n ' .format (
181201 h = h ,
182202 m = m
183203 )])
204+
184205 # trusted
185206 hba .writelines (["local all all trust\n " ])
186207 hba .writelines (["host test trusted 0.0.0.0/0 trust\n " ])
@@ -193,26 +214,11 @@ def configure_cluster(self):
193214
194215 def initialize_database (self ):
195216 super ().initialize_database ()
217+
196218 with self .cluster .connection (user = 'test' ) as db :
197- db .execute (
198- """
199- CREATE USER md5 WITH
200- ENCRYPTED PASSWORD 'md5_password'
201- ;
202-
203- -- crypt doesn't work with encrypted passwords:
204- -- http://www.postgresql.org/docs/8.2/interactive/auth-methods.html#AUTH-PASSWORD
205- CREATE USER crypt WITH
206- UNENCRYPTED PASSWORD 'crypt_password'
207- ;
208-
209- CREATE USER password WITH
210- ENCRYPTED PASSWORD 'password_password'
211- ;
212-
213- CREATE USER trusted;
214- """
215- )
219+ db .execute (self .mk_common_users )
220+ if self .check_crypt_user :
221+ db .execute (self .mk_crypt_user )
216222
217223 def test_pg_open_SQL_ASCII (self ):
218224 # postgresql.open
@@ -364,7 +370,7 @@ def test_dbapi_connect(self):
364370 MD5 .cursor ().execute , 'select 1'
365371 )
366372
367- if self .do_crypt :
373+ if self .check_crypt_user :
368374 CRYPT = dbapi20 .connect (
369375 user = 'crypt' ,
370376 database = 'test' ,
@@ -449,7 +455,7 @@ def test_md5_connect(self):
449455 self .assertEqual (c .prepare ('select current_user' ).first (), 'md5' )
450456
451457 def test_crypt_connect (self ):
452- if self .do_crypt :
458+ if self .check_crypt_user :
453459 c = self .cluster .connection (
454460 user = 'crypt' ,
455461 password = 'crypt_password' ,
0 commit comments