def test_Shop_socket_timeout_backoff(self, mocked_current, mocked_sleep): """ Test case to verify that we backoff for 5 times when 'socket.timeout' error occurs """ # mock 'Shop' call and raise timeout error mocked_current.side_effect = socket.timeout( "The read operation timed out") Context.config = {"api_key": "test_api_key", "shop": "test_shop"} try: # function call tap_shopify.initialize_shopify_client() except socket.timeout: pass # verify we backoff 5 times self.assertEquals(mocked_current.call_count, 5)
def test_timeout_value_not_passed_in_config__initialize_shopify_client( self, mocked_current, mocked_set_timeout): """ Test case to verify that the default value is used when we do not pass request timeout value from config """ # initialize config Context.config = { "start_date": "2021-01-01", "api_key": "test_api_key", "shop": "test_shop", "results_per_page": 50 } # function call tap_shopify.initialize_shopify_client() # verify the timeout is set as expected mocked_set_timeout.assert_called_with(300)
def test_Shop_pyactiveresource_error_timeout_backoff( self, mocked_current, mocked_sleep): """ Test case to verify that we backoff for 5 times when 'pyactiveresource.connection.Error' error occurs """ # mock 'Shop' call and raise timeout error mocked_current.side_effect = pyactiveresource.connection.Error( 'urlopen error _ssl.c:1074: The handshake operation timed out') Context.config = {"api_key": "test_api_key", "shop": "test_shop"} try: # function call tap_shopify.initialize_shopify_client() except pyactiveresource.connection.Error: pass # verify we backoff 5 times self.assertEquals(mocked_current.call_count, 5)
def test_timeout_string_value_passed_in_config__initialize_shopify_client( self, mocked_current, mocked_set_timeout): """ Test case to verify that the value we passed on config is set as request timeout value """ # initialize config Context.config = { "start_date": "2021-01-01", "api_key": "test_api_key", "shop": "test_shop", "results_per_page": 50, "request_timeout": "100" } # function call tap_shopify.initialize_shopify_client() # verify the timeout is set as expected mocked_set_timeout.assert_called_with(100)