def test_api_url_read_from_env_var(self, unused_jwt_encode, mock_glob, open_mock): apikey_auth = SeerApiKeyAuth(api_key_id='id', api_key_path=None, api_key='key') params = apikey_auth.get_connection_parameters() assert apikey_auth.api_url == 'https://random-sdk.url' assert params['url'] == 'https://random-sdk.url/graphql' open_mock.assert_not_called() mock_glob.assert_not_called()
def test_get_connection_parameters_no_decode(self, unused_jwt_encode, unused_glob, open_mock): apikey_auth = SeerApiKeyAuth(api_key_id='id', api_key_path='path/seerpy.pem') params = apikey_auth.get_connection_parameters() assert params == { 'url': 'https://sdk-au.seermedical.com/api/graphql', 'headers': { 'Authorization': 'Bearer an_unencoded_key' }, 'use_json': True, 'timeout': 30 } open_mock.assert_called_with('path/seerpy.pem', 'r')
def test_multiple_key_files_with_no_match(self, mock_glob, open_mock): # setup mock_glob.return_value = ['path/seerpy.pem', 'path/seerpy.id.pem'] # run test and check result with pytest.raises(ValueError, match='No default API key file found'): SeerApiKeyAuth(api_key_id=None, api_key_path=None) open_mock.assert_not_called()
def test_no_files(self, mock_glob, open_mock): # setup mock_glob.return_value = [] # run test and check result with pytest.raises(ValueError, match='No API key file available'): SeerApiKeyAuth(api_key_id=None, api_key_path=None) open_mock.assert_not_called()
def test_key_no_id(self, unused_glob, open_mock): # run test and check result with pytest.raises( ValueError, match= 'api_key_id and region or api_url must be provided with api_key' ): SeerApiKeyAuth(api_key_id=None, api_key_path=None, api_key='key') open_mock.assert_not_called()
def test_default_key_file_but_no_id(self, mock_glob, open_mock): # setup mock_glob.return_value = ['path/seerpy.pem', 'path/seerpy.default.pem'] # run test and check result with pytest.raises(ValueError, match='No API key id found in key file name'): SeerApiKeyAuth(api_key_id=None, api_key_path=None) open_mock.assert_not_called()
def test_id_with_no_matching_file(self, mock_glob, open_mock): # setup mock_glob.return_value = ['path/seerpy.pem', 'path/seerpy.id2.uk.pem'] # run test and check result with pytest.raises( ValueError, match='No API key file matches the API key id provided'): SeerApiKeyAuth(api_key_id='id', api_key_path=None) open_mock.assert_not_called()
def test_key(self, mock_glob, open_mock): # run test result = SeerApiKeyAuth(api_key_id='id', api_key_path=None, api_key='key') # check result assert result.api_key_id == 'id' assert result.api_key == 'key' assert result.api_url == 'https://sdk-au.seermedical.com/api' open_mock.assert_not_called() mock_glob.assert_not_called()
def test_multiple_regions(self, mock_glob, open_mock): # setup mock_glob.return_value = [ 'path/seerpy.id.pem', 'path/seerpy.id.uk.au.pem' ] # run test and check result with pytest.raises(ValueError, match='Multiple regions found in key file name'): SeerApiKeyAuth(api_key_id=None, api_key_path=None) open_mock.assert_not_called()
def test_id_with_matching_file(self, mock_glob, open_mock): # setup mock_glob.return_value = ['path/seerpy.pem', 'path/seerpy.id.uk.pem'] # run test result = SeerApiKeyAuth(api_key_id='id', api_key_path=None) # check result assert result.api_key_id == 'id' open_mock.assert_called_with('path/seerpy.id.uk.pem', 'r') assert result.api_key == '1234' assert result.api_url == 'https://sdk-uk.seermedical.com/api'
def test_id_and_key(self, mock_glob, open_mock): # setup mock_glob.return_value = [] # run test result = SeerApiKeyAuth(api_key_id='id', api_key_path='path/seerpy.pem') # check result assert result.api_key_id == 'id' open_mock.assert_called_with('path/seerpy.pem', 'r') assert result.api_key == '1234' assert result.api_url == 'https://sdk-au.seermedical.com/api'
def test_multiple_default_key_files_with_matching_region( self, mock_glob, open_mock): # setup mock_glob.return_value = [ 'path/seerpy.default.pem', 'path/seerpy.default.id.au.pem' ] # run test result = SeerApiKeyAuth(api_key_id=None, api_key_path=None) # check result assert result.api_key_id == 'id' open_mock.assert_called_with('path/seerpy.default.id.au.pem', 'r') assert result.api_key == '1234' assert result.api_url == 'https://sdk-au.seermedical.com/api'