def test_request_timeout_and_backoff(self, mock_get_token, mock_request): """ Check whether the request backoffs properly for request() for 5 times in case of Timeout error. """ mock_request.side_effect = Timeout client = RechargeClient("dummy_access_token", "dummy_user_agent", 300) with self.assertRaises(Timeout): client.request("GET") self.assertEquals(mock_request.call_count, 5)
def test_default_value_request_timeout(self, mock_get, mock_request): """ Unit tests to ensure that request timeout is set based default value """ config = {"access_token": "dummy_at", "user_agent": "dummy_ua"} client = RechargeClient(**config) client.request("GET", "dummy_path") mock_request.assert_called_with( 'GET', 'https://api.rechargeapps.com/dummy_path', stream=True, timeout=600, headers={ 'X-Recharge-Access-Token': 'dummy_at', 'Accept': 'application/json', 'User-Agent': 'dummy_ua' })
def test_check_access_token_timeout_and_backoff(self, mocked_request): """ Check whether the request backoffs properly for __enter__() for 5 times in case of Timeout error. """ mocked_request.side_effect = Timeout config = {"access_token": "dummy_at", "user_agent": "dummy_ua"} # initialize 'RechargeClient' try: with RechargeClient(config['access_token'], config['user_agent'], config.get('request_timeout')) as client: pass except Timeout: pass # verify that we backoff for 5 times self.assertEquals(mocked_request.call_count, 5)
def main(): parsed_args = singer.utils.parse_args(REQUIRED_CONFIG_KEYS) with RechargeClient(parsed_args.config['access_token'], parsed_args.config['user_agent']) as client: state = {} if parsed_args.state: state = parsed_args.state if parsed_args.discover: do_discover() elif parsed_args.catalog: sync(client=client, catalog=parsed_args.catalog, state=state, start_date=parsed_args.config['start_date'])
def main(): """Entrypoint function for tap.""" parsed_args = utils.parse_args(REQUIRED_CONFIG_KEYS) with RechargeClient(parsed_args.config['access_token'], parsed_args.config['user_agent']) as client: state = {} if parsed_args.state: state = parsed_args.state if parsed_args.discover: do_discover() elif parsed_args.catalog: sync(client=client, catalog=parsed_args.catalog, state=state, config=parsed_args.config)
def test_sync_for_valid_replication_key(self, mocked_write_record, mocked_transformer, mocked_get_records): """Test sync method when record has a valid replication key""" # Mocked config parameters mocked_config = { "access_token": "dummy_token", "start_date": "2021-01-01T00:00:00Z" } # Client object client = RechargeClient(mocked_config["access_token"]) # Stream object stream_obj = IncrementalStream(client) # Transformer object transfomer = singer.Transformer # Dummy parameters stream_obj.tap_stream_id = "orders" stream_obj.replication_key = "updated_at" mocked_state = {} mocked_schema = {} mocked_stream_metadata = {} # Mocked return value for the get_records call mocked_get_records.return_value = [ {"id": "1", "updated_at": "2021-09-16T00:06:34.000000Z"}, {"id": "2", "updated_at": "2020-09-16T00:00:34.000000Z"}, {"id": "3", "updated_at": "2021-10-11T00:01:32.000000Z"}, {"id": "4", "updated_at": "2021-08-21T00:51:10.000000Z"}] # Sync function call state = stream_obj.sync(mocked_state, mocked_schema, mocked_stream_metadata, mocked_config, transfomer) # Expected state for the bookmark expected_state = {"bookmarks": {"orders": "2021-10-11T00:01:32.000000Z"}} # Check for every mocked record is written self.assertEqual(mocked_write_record.call_count, 3) # Check state is written as expected self.assertEqual(state, expected_state)