def test_add_timeout_with_retry(mocker): asset_name = "traintuple" m_post = mock_requests(mocker, "post", response={"pkhash": "a-key"}, status=408) m_get = mock_requests(mocker, "get", response={"pkhash": "a-key"}) asset = rest_client.Client(CONFIG).add(asset_name) assert len(m_post.call_args_list) == 1 assert len(m_get.call_args_list) == 1 assert asset == {"pkhash": "a-key"}
def test_request_http_errors(mocker, status_code, http_response, sdk_exception): m = mock_requests(mocker, "post", response=http_response, status=status_code) with pytest.raises(sdk_exception): rest_client.Client(CONFIG).add('http://foo', {}) assert len(m.call_args_list) == 1
def test_add_timeout_with_retry(mocker): asset_name = "traintuple" responses = [ mock_response(response={"pkhash": "a-key"}, status=408), mock_response(response={"pkhash": "a-key"}), ] m_post = mock_requests_responses(mocker, "post", responses) asset = rest_client.Client(CONFIG).add(asset_name, retry_timeout=60) assert len(m_post.call_args_list) == 2 assert asset == {"pkhash": "a-key"}
def __init__(self, config_path=None, profile_name=None, user_path=None): self._cfg_manager = cfg.Manager(config_path or cfg.DEFAULT_PATH) self._usr_manager = usr.Manager(user_path or usr.DEFAULT_PATH) self._current_profile = None self._profiles = {} self.client = rest_client.Client() self._profile_name = 'default' if profile_name: self._profile_name = profile_name self.set_profile(profile_name) # set current logged user if exists self.set_user()
def __init__(self, config_path=None, profile_name=None, user_path=None, token=None, retry_timeout=DEFAULT_RETRY_TIMEOUT): self._cfg_manager = cfg.Manager(config_path or cfg.DEFAULT_PATH) self._usr_manager = usr.Manager(user_path or usr.DEFAULT_PATH) self._current_profile = None self._profiles = {} self.client = rest_client.Client() self._profile_name = 'default' self._retry_timeout = retry_timeout if profile_name: self._profile_name = profile_name self.set_profile(profile_name) # set current logged user if exists self.set_user() if token: self._set_token(token)
def test_request_connection_error(mocker): mocker.patch('substra.sdk.rest_client.requests.post', side_effect=requests.exceptions.ConnectionError) with pytest.raises(exceptions.ConnectionError): rest_client.Client(CONFIG).add('foo', {})
def test_post_success(mocker, config): m = mock_requests(mocker, "post", response={}) rest_client.Client(config).add('http://foo', {}) assert len(m.call_args_list) == 1