Skip to content

Commit db3a2fe

Browse files
committed
test: fix mocks in unit tests
1 parent a813bee commit db3a2fe

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

aws_advanced_python_wrapper/read_write_splitting_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def _initialize_writer_connection(self):
216216
)
217217
self._set_writer_connection(conn, writer_host)
218218
self._switch_current_connection_to(conn, writer_host)
219+
return None
219220

220221
def _switch_connection_if_required(self, read_only: bool):
221222
current_conn = self._plugin_service.current_connection

tests/unit/test_read_write_splitting_plugin.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def connect_side_effect(host: HostInfo, props, plugin):
327327
)
328328

329329
provider = SqlAlchemyPooledConnectionProvider(
330-
lambda _, __: {"pool_size": 3}, None, 180000000000, 600000000000 # 3 minutes
330+
lambda _, __: {"pool_size": 3}, None, None, 180000000000, 600000000000 # 3 minutes
331331
) # 10 minutes
332332

333333
conn_provider_manager_mock = mocker.MagicMock()
@@ -345,7 +345,7 @@ def connect_side_effect(host: HostInfo, props, plugin):
345345
)
346346
plugin = SimpleReadWriteSplittingPlugin(plugin_service_mock, srw_props)
347347

348-
spy = mocker.spy(plugin, "_close_connection_if_idle")
348+
spy = mocker.spy(plugin, "_close_connection")
349349

350350
plugin._switch_connection_if_required(True)
351351
plugin._switch_connection_if_required(False)
@@ -373,7 +373,7 @@ def connect_side_effect(host: HostInfo, props, plugin):
373373
)
374374

375375
provider = SqlAlchemyPooledConnectionProvider(
376-
lambda _, __: {"pool_size": 3}, None, 180000000000, 600000000000 # 3 minutes
376+
lambda _, __: {"pool_size": 3}, None, None, 180000000000, 600000000000 # 3 minutes
377377
) # 10 minutes
378378

379379
conn_provider_manager_mock = mocker.MagicMock()
@@ -391,7 +391,7 @@ def connect_side_effect(host: HostInfo, props, plugin):
391391
)
392392
plugin = SimpleReadWriteSplittingPlugin(plugin_service_mock, srw_props)
393393

394-
spy = mocker.spy(plugin, "_close_connection_if_idle")
394+
spy = mocker.spy(plugin, "_close_connection")
395395

396396
plugin._switch_connection_if_required(True)
397397
plugin._switch_connection_if_required(False)
@@ -476,7 +476,7 @@ def test_connect_non_initial_connection_read_write_splitting(
476476
connect_func_mock.assert_called()
477477

478478

479-
def test_set_read_only_true_one_host_read_write_splitting(plugin_service_mock, read_write_splitting_plugin):
479+
def test_set_read_only_true_one_host_read_write_splitting(plugin_service_mock, read_write_splitting_plugin, writer_conn_mock):
480480
plugin_service_mock.hosts = [writer_host]
481481

482482
read_write_splitting_plugin._writer_connection = writer_conn_mock
@@ -490,7 +490,7 @@ def test_set_read_only_true_one_host_read_write_splitting(plugin_service_mock, r
490490

491491

492492
def test_connect_error_updating_host_read_write_splitting(
493-
plugin_service_mock, read_write_splitting_plugin, host_list_provider_service_mock, connect_func_mock, mocker):
493+
plugin_service_mock, read_write_splitting_plugin, host_list_provider_service_mock, connect_func_mock, mocker, reader_conn_mock):
494494
def get_host_role_side_effect(conn):
495495
if conn == reader_conn_mock:
496496
return None
@@ -516,7 +516,7 @@ def get_host_role_side_effect(conn):
516516

517517

518518
# Tests for the Simple Read/Write Splitting Plugin
519-
def test_set_read_only_true_srw(srw_plugin, plugin_service_mock, reader_conn_mock):
519+
def test_set_read_only_true_srw(srw_plugin, plugin_service_mock, reader_conn_mock, writer_conn_mock):
520520
plugin_service_mock.current_connection = writer_conn_mock
521521
plugin_service_mock.connect.return_value = reader_conn_mock
522522

@@ -534,7 +534,7 @@ def test_set_read_only_true_srw(srw_plugin, plugin_service_mock, reader_conn_moc
534534

535535

536536
def test_set_read_only_false_srw(
537-
srw_plugin, plugin_service_mock, reader_conn_mock, writer_conn_mock,):
537+
srw_plugin, plugin_service_mock, reader_conn_mock, writer_conn_mock):
538538
plugin_service_mock.current_connection = reader_conn_mock
539539
plugin_service_mock.connect.return_value = writer_conn_mock
540540

@@ -719,7 +719,7 @@ def test_connect_non_rds_cluster_endpoint_srw(
719719

720720

721721
def test_connect_non_rds_cluster_endpoint_with_verification_srw(
722-
plugin_service_mock, connect_func_mock, writer_conn_mock, mocker,):
722+
plugin_service_mock, connect_func_mock, writer_conn_mock, mocker, host_list_provider_service_mock):
723723
custom_host = HostInfo(
724724
host="custom-db.example.com", port=TEST_PORT, role=HostRole.WRITER
725725
)

0 commit comments

Comments
 (0)