Skip to content

Commit dc4b4c3

Browse files
author
vshepard
committed
Move _get_ssl_options in separate function
1 parent e729c2f commit dc4b4c3

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

testgres/operations/os_ops.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,27 @@ def get_pid(self):
124124
def get_process_children(self, pid):
125125
raise NotImplementedError()
126126

127+
def _get_ssl_options(self):
128+
"""
129+
Determine the SSL options based on available modules.
130+
"""
131+
if self.conn_params.skip_ssl:
132+
if 'psycopg2' in sys.modules:
133+
return {"sslmode": "disable"}
134+
elif 'pg8000' in sys.modules:
135+
return {"ssl_context": None}
136+
return {}
137+
127138
# Database control
128139
def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
129-
ssl_options = {"sslmode": "disable"} if self.conn_params.skip_ssl and 'psycopg2' in sys.modules else {}
140+
ssl_options = self._get_ssl_options()
130141
conn = pglib.connect(
131142
host=host,
132143
port=port,
133144
database=dbname,
134145
user=user,
135146
password=password,
136-
**({"ssl_context": None} if self.conn_params.skip_ssl and 'pg8000' in sys.modules else ssl_options)
147+
**ssl_options
137148
)
138149

139150
return conn

tests/test_simple.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,11 @@ def test_parse_pg_version(self):
10391039
def test_the_same_port(self):
10401040
with get_new_node() as node:
10411041
node.init().start()
1042-
with get_new_node() as node2:
1043-
node2.port = node.port
1044-
node2.init().start()
1042+
with get_new_node() as node2:
1043+
node2.port = node.port
1044+
# _should_free_port is true if port was set up manually
1045+
node2._should_free_port = False
1046+
node2.init().start()
10451047

10461048
def test_make_simple_with_bin_dir(self):
10471049
with get_new_node() as node:

0 commit comments

Comments
 (0)