def test_get_api_key_api_error(self, mock_validate_api_key, mock_prompt): with fake_creds('.jovian-get-api-key', 'credentials.json'): creds = { "WEBAPP_URL": "https://staging.jovian.ml/", "ORG_ID": "staging", "API_URL": "https://api-staging.jovian.ai" } write_creds(creds) with self.assertRaises(ApiError): get_api_key()
def test_get_api_key_api_error(mock_validate_api_key, mock_prompt): with fake_creds(): creds = { "WEBAPP_URL": "https://staging.jovian.ai/", "ORG_ID": "staging", "API_URL": "https://api-staging.jovian.ai" } write_creds(creds) with pytest.raises(ApiError): get_api_key()
def _h(): """Create authorization header with API key""" return {"Authorization": "Bearer " + get_api_key(), "x-jovian-source": "library", "x-jovian-library-version": __version__, "x-jovian-guest": get_guest_key(), "x-jovian-org": read_org_id()}
def _h(): """Create a header to provide library metadata""" return {"Authorization": "Bearer " + get_api_key(), "x-jovian-source": "library", "x-jovian-library-version": __version__, "x-jovian-command": "add-slack", "x-jovian-guest": get_guest_key(), "x-jovian-org": read_org_id()}
def test_get_api_key_request_once(mock_validate_api_key, mock_prompt): with fake_creds(): creds = { "WEBAPP_URL": "https://staging.jovian.ai/", "ORG_ID": "staging", "API_URL": "https://api-staging.jovian.ai" } write_creds(creds) assert get_api_key() == "fake_api_key"
def test_get_api_key(mock_validate_api_key): with fake_creds(): creds = { "WEBAPP_URL": "https://staging.jovian.ml/", "ORG_ID": "staging", "API_KEY": "fake_api_key", "API_URL": "https://api-staging.jovian.ai" } write_creds(creds) assert get_api_key() == "fake_api_key"
def test_get_api_key_request_once(self, mock_validate_api_key, mock_prompt): with fake_creds('.jovian-get-api-key', 'credentials.json'): creds = { "WEBAPP_URL": "https://staging.jovian.ml/", "ORG_ID": "staging", "API_URL": "https://api-staging.jovian.ai" } write_creds(creds) assert get_api_key() == "fake_api_key"
def _request_wrapper(*args, **kwargs): for i in range(2): res = request(*args, **kwargs) if res.status_code == 401: log('The current API key is invalid or expired.', error=True) purge_api_key() # This will ensure that fresh api token is requested if 'headers' in kwargs: kwargs['headers'][ 'Authorization'] = "Bearer " + get_api_key() else: return res return res