diff --git a/test/client/test_connections.py b/test/client/test_connections.py index 89445b3..f8ec9ed 100644 --- a/test/client/test_connections.py +++ b/test/client/test_connections.py @@ -34,13 +34,15 @@ def setUp(self): def test_connection_pool(self): # When - actual = _ConnectionPool() + client = None + actual = _ConnectionPool(client) # Then self.assertEqual(0, actual._size) async def test_pool_get_connection_new(self): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' scheme = 'ws' # When @@ -53,7 +55,8 @@ async def test_pool_get_connection_new(self): async def test_pool_get_connection_existing(self): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' scheme = 'ws' expected = await pool._get_connection(uri, scheme, True, True) @@ -66,7 +69,8 @@ async def test_pool_get_connection_existing(self): async def test_pool_get_connection_closed(self): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' scheme = 'ws' expected = await pool._get_connection(uri, scheme, True, True) @@ -81,7 +85,8 @@ async def test_pool_get_connection_closed(self): async def test_pool_remove_connection_existing(self): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' scheme = 'ws' connection = await pool._get_connection(uri, scheme, True, True) @@ -94,7 +99,8 @@ async def test_pool_remove_connection_existing(self): async def test_pool_remove_connection_non_existing(self): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' # When await pool._remove_connection(uri) @@ -104,7 +110,8 @@ async def test_pool_remove_connection_non_existing(self): @patch('swimos.client._connections._WSConnection._subscribe', new_callable=MockAsyncFunction) async def test_pool_add_downlink_view_existing_connection(self, mock_subscribe): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' scheme = 'ws' connection = await pool._get_connection(uri, scheme, True, True) @@ -126,7 +133,8 @@ async def test_pool_add_downlink_view_existing_connection(self, mock_subscribe): @patch('swimos.client._connections._WSConnection._subscribe', new_callable=MockAsyncFunction) async def test_pool_add_downlink_view_non_existing_connection(self, mock_subscribe): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' client = SwimClient() client._has_started = True @@ -143,7 +151,8 @@ async def test_pool_add_downlink_view_non_existing_connection(self, mock_subscri @patch('swimos.client._connections._WSConnection._unsubscribe', new_callable=MockAsyncFunction) async def test_pool_remove_downlink_view_existing_connection_open(self, mock_unsubscribe, mock_subscribed): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' client = SwimClient() client._has_started = True @@ -164,7 +173,8 @@ async def test_pool_remove_downlink_view_existing_connection_open(self, mock_uns @patch('swimos.client._connections._WSConnection._unsubscribe', new_callable=MockAsyncFunction) async def test_pool_remove_downlink_view_existing_connection_closed(self, mock_unsubscribe, mock_subscribe): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' scheme = 'ws' client = SwimClient() @@ -186,7 +196,8 @@ async def test_pool_remove_downlink_view_existing_connection_closed(self, mock_u @patch('swimos.client._connections._DownlinkManagerPool._deregister_downlink_view', new_callable=MockAsyncFunction) async def test_pool_remove_downlink_view_non_existing_connection(self, mock_deregister_downlink_view): # Given - pool = _ConnectionPool() + client = None + pool = _ConnectionPool(client) uri = 'ws://foo_bar:9000' client = SwimClient() client._has_started = True @@ -205,7 +216,8 @@ async def test_ws_connection(self): host_uri = 'ws://localhost:9001' scheme = 'ws' # When - actual = _WSConnection(host_uri, scheme, True, True) + client = None + actual = _WSConnection(client, host_uri, scheme, True, True) # Then self.assertEqual(host_uri, actual.host_uri) self.assertIsNone(actual.websocket) @@ -217,7 +229,8 @@ async def test_ws_connection_subscribe_single(self, mock_add_view, mock_websocke # Given host_uri = 'ws://localhost:9001' scheme = 'ws' - actual = _WSConnection(host_uri, scheme, True, True) + actual = client = None + actual = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -240,7 +253,8 @@ async def test_ws_connection_subscribe_multiple(self, mock_add_view, mock_websoc # Given host_uri = 'ws://1.1.1.1:9001' scheme = 'ws' - actual = _WSConnection(host_uri, scheme, True, True) + actual = client = None + actual = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True @@ -272,7 +286,8 @@ async def test_ws_connection_unsubscribe_all(self, mock_remove_view, mock_add_vi # Given host_uri = 'ws://0.0.0.0:9001' scheme = 'ws' - actual = _WSConnection(host_uri, scheme, True, True) + actual = client = None + actual = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -300,7 +315,8 @@ async def test_ws_connection_unsubscribe_one(self, mock_remove_view, mock_add_vi # Given host_uri = 'ws://1.2.3.4:9001' scheme = 'ws' - actual = _WSConnection(host_uri, scheme, True, True) + actual = client = None + actual = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True @@ -334,7 +350,8 @@ async def test_ws_connection_open_new(self, mock_websocket): # Given host_uri = 'ws://1.2.3.4:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) # When await connection._open() # Then @@ -346,7 +363,8 @@ async def test_wss_connection_open_new(self, mock_websocket): # Given host_uri = 'wss://1.2.3.4:9001' scheme = 'wss' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) # When await connection._open() # Then @@ -359,7 +377,8 @@ async def test_ws_connection_open_error(self, mock_websocket): MockWebsocket.get_mock_websocket().raise_exception = True host_uri = 'ws://1.2.3.4:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) # When with self.assertRaises(Exception) as error: # noinspection PyTypeChecker @@ -376,7 +395,8 @@ async def test_wss_connection_open_error(self, mock_websocket): MockWebsocket.get_mock_websocket().raise_exception = True host_uri = 'wss://1.2.3.4:9001' scheme = 'wss' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) # When with self.assertRaises(Exception) as error: # noinspection PyTypeChecker @@ -392,7 +412,8 @@ async def test_ws_connection_open_already_opened(self, mock_websocket): # Given host_uri = 'ws://1.2.3.4:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) await connection._open() # When await connection._open() @@ -405,7 +426,8 @@ async def test_ws_connection_close_opened(self, mock_websocket): # Given host_uri = 'ws://1.2.3.4:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) await connection._open() # When await connection._close() @@ -419,7 +441,8 @@ async def test_ws_connection_close_missing_websocket(self, mock_websocket): # Given host_uri = 'ws://1.2.3.4:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) # When await connection._close() # Then @@ -432,7 +455,8 @@ async def test_ws_connection_close_already_closed(self, mock_websocket): # Given host_uri = 'ws://5.5.5.5:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) await connection._open() await connection._close() # When @@ -448,7 +472,8 @@ async def test_ws_connection_send_message_existing_websocket_single(self, mock_w host_uri = 'ws://1.2.3.4:9001' message = 'Hello, World' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) await connection._open() # When await connection._send_message(message) @@ -463,7 +488,8 @@ async def test_ws_connection_send_message_existing_websocket_multiple(self, mock first_message = 'Hello, World' second_message = 'Hello, Friend' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) await connection._open() # When await connection._send_message(first_message) @@ -479,7 +505,8 @@ async def test_ws_connection_send_message_non_existing_websocket(self, mock_webs host_uri = 'ws://1.2.3.4:9001' message = 'Hello, World' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) # When await connection._send_message(message) # Then @@ -492,7 +519,8 @@ async def test_ws_connection_send_message_closed(self, mock_websocket): host_uri = 'ws://1.2.3.4:9001' message = 'Hello, World' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) await connection._open() await connection._close() # When @@ -506,7 +534,8 @@ async def test_ws_connection_wait_for_message_closed(self): # Given host_uri = 'ws://1.2.3.4:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) # When await connection._wait_for_messages() # Then @@ -520,7 +549,8 @@ async def test_ws_connection_wait_for_message_receive_single(self, mock_receive_ # Given host_uri = 'ws://1.2.3.4:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) MockWebsocket.get_mock_websocket().connection = connection client = SwimClient() @@ -551,7 +581,8 @@ async def test_ws_connection_wait_for_message_receive_multiple(self, mock_receiv # Given host_uri = 'ws://2.2.2.2:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) MockWebsocket.get_mock_websocket().connection = connection mock_receive_message.set_call_count(3) @@ -594,7 +625,8 @@ async def test_ws_connection_wait_for_message_receive_exception(self, mock_recei # Given host_uri = 'ws://5.5.5.5:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) MockWebsocket.get_mock_websocket().connection = connection mock_websocket.set_raise_exception(True) @@ -795,7 +827,8 @@ async def test_downlink_manager(self): # Given host_uri = 'ws://5.5.5.5:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) # When actual = _DownlinkManager(connection) # Then @@ -810,7 +843,8 @@ async def test_downlink_manager_open_new(self, mock_schedule_task): # Given host_uri = 'ws://5.5.5.5:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -833,7 +867,8 @@ async def test_downlink_manager_open_existing(self, mock_schedule_task): # Given host_uri = 'ws://5.5.5.5:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -857,7 +892,8 @@ async def test_downlink_manager_close_running(self, mock_schedule_task): # Given host_uri = 'ws://1.2.3.4:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -880,7 +916,8 @@ async def test_downlink_manager_close_stopped(self, mock_schedule_task): # Given host_uri = 'ws://4.3.2.1:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -901,7 +938,8 @@ async def test_downlink_manager_init_downlink_model(self): # Given host_uri = 'ws://100.100.100.100:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -926,7 +964,8 @@ async def test_downlink_manager_init_downlink_model_strict_classes(self): # Given host_uri = 'ws://100.100.100.100:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client.start() downlink_view = client.downlink_value() @@ -957,7 +996,8 @@ async def test_downlink_manager_add_view_single(self, mock_schedule_task, mock_s # Given host_uri = 'ws://99.99.99.99:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -986,7 +1026,8 @@ async def test_downlink_manager_add_view_multiple(self, mock_schedule_task, mock # Given host_uri = 'ws://11.22.33.44:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True first_downlink_view = client.downlink_value() @@ -1025,7 +1066,8 @@ async def test_downlink_manager_remove_view_single(self, mock_schedule_task, moc # Given host_uri = 'ws://11.11.11.11:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -1055,7 +1097,8 @@ async def test_downlink_manager_remove_view_multiple(self, mock_schedule_task, m # Given host_uri = 'ws://44.33.22.11:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True first_downlink_view = client.downlink_value() @@ -1092,7 +1135,8 @@ async def test_downlink_manager_remove_view_non_existing(self, mock_schedule_tas # Given host_uri = 'ws://66.66.66.66:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -1114,7 +1158,8 @@ async def test_downlink_manager_receive_message_linked(self, mock_schedule_task, # Given host_uri = 'ws://66.66.66.66:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -1136,7 +1181,8 @@ async def test_downlink_manager_receive_message_synced(self, mock_schedule_task, # Given host_uri = 'ws://11.11.11.11:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -1158,7 +1204,8 @@ async def test_downlink_manager_receive_message_event(self, mock_schedule_task, # Given host_uri = 'ws://33.33.33.33:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -1181,7 +1228,8 @@ async def test_downlink_manager_receive_message_multiple(self, mock_schedule_tas # Given host_uri = 'ws://44.44.44.44:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -1210,7 +1258,8 @@ async def test_downlink_manager_subscribers_did_set_single(self, mock_schedule_t # Given host_uri = 'ws://4.3.2.1:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_value() @@ -1235,7 +1284,8 @@ async def test_downlink_manager_subscribers_did_set_multiple(self, mock_schedule # Given host_uri = 'ws://10.9.8.7:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True did_set_callback = mock_did_set_callback @@ -1287,7 +1337,8 @@ async def test_downlink_manager_subscribers_on_event_single(self, mock_schedule_ # Given host_uri = 'ws://4.3.2.1:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_event() @@ -1311,7 +1362,8 @@ async def test_downlink_manager_subscribers_on_event_multiple(self, mock_schedul # Given host_uri = 'ws://10.9.8.7:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True on_event_callback = mock_on_event_callback @@ -1352,7 +1404,8 @@ async def test_downlink_manager_subscribers_did_update_single(self, mock_schedul # Given host_uri = 'ws://4.3.2.1:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_map() @@ -1378,7 +1431,8 @@ async def test_downlink_manager_subscribers_did_update_multiple(self, mock_sched # Given host_uri = 'ws://10.9.8.7:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True did_update_callback = mock_did_update_callback @@ -1425,7 +1479,8 @@ async def test_downlink_manager_subscribers_did_remove_single(self, mock_schedul # Given host_uri = 'ws://4.3.2.1:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_map() @@ -1450,7 +1505,8 @@ async def test_downlink_manager_subscribers_did_remove_multiple(self, mock_sched # Given host_uri = 'ws://10.9.8.7:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True did_remove_callback = mock_on_event_callback @@ -1494,7 +1550,8 @@ async def test_downlink_manager_close_views_single(self, mock_schedule_task, moc # Given host_uri = 'ws://4.3.2.1:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True downlink_view = client.downlink_map() @@ -1514,7 +1571,8 @@ async def test_downlink_manager_close_views_multiple(self, mock_schedule_task, m # Given host_uri = 'ws://4.3.2.1:9001' scheme = 'ws' - connection = _WSConnection(host_uri, scheme, True, True) + client = None + connection = _WSConnection(client, host_uri, scheme, True, True) client = SwimClient() client._has_started = True actual = _DownlinkManager(connection)