コード例 #1
0
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"}
コード例 #2
0
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
コード例 #3
0
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"}
コード例 #4
0
ファイル: client.py プロジェクト: almoisson/substra
    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()
コード例 #5
0
ファイル: client.py プロジェクト: aashish24/substra
    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)
コード例 #6
0
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', {})
コード例 #7
0
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