Example #1
0
  def test_make_get_request_to_ai_platform_404_error(
      self, mock_request_header, mock_get_func):
    mock_request_header.return_value = {}

    mock_response = mock.Mock(spec=MockResponse)
    type(mock_response()).status_code = mock.PropertyMock(return_value=404)
    mock_get_func.return_value = mock_response()

    with self.assertRaisesRegex(
        ValueError,
        ('Target URI .* returns HTTP 404 error.\n'
         'Please check if the project, model, and version names '
         'are given correctly.')):
      http_utils.make_get_request_to_ai_platform('uri/test_uri')
    def test_make_get_request_to_ai_platform_other_errors(
            self, mock_request_header, mock_get_func):
        mock_request_header.return_value = {}

        mock_response = mock.Mock(spec=MockResponse)
        type(mock_response()).status_code = mock.PropertyMock(return_value=501)
        type(mock_response()).text = mock.PropertyMock(
            return_value='test error')
        mock_get_func.return_value = mock_response()

        with self.assertRaisesRegex(ValueError,
                                    ('Target URI .* returns HTTP 501 error.\n'
                                     'Please check the raw error message: \n'
                                     'test error')):
            http_utils.make_get_request_to_ai_platform('uri/test_uri')
    def test_make_get_request_to_ai_platform(self, mock_request_header,
                                             mock_get_func):
        mock_request_header.return_value = {}

        mock_response = mock.Mock(spec=MockResponse)
        type(mock_response()).status_code = mock.PropertyMock(return_value=200)
        mock_response().json.return_value = 'results'
        mock_get_func.return_value = mock_response()

        res = http_utils.make_get_request_to_ai_platform('uri/test_uri')
        self.assertTrue(mock_get_func.called)
        self.assertEqual(res, 'results')
    def _get_deployment_uri(self):
        """A method to get the depolyment uri of the model.

    Returns:
      A string uri of a gcs bucket.

    Raises:
      KeyError: This error will be raised if the 'deploymentUri' key is
        missing from the returned version information.
    """
        response = http_utils.make_get_request_to_ai_platform(
            self._endpoint, self._credentials)

        if 'deploymentUri' not in response:
            raise KeyError(
                'There is no deploymentUri information in this version')

        return response['deploymentUri']
Example #5
0
def _get_deployment_uri(
    model_endpoint_uri: str,
    credentials: Optional[google.auth.credentials.Credentials] = None) -> str:
  """Gets the deployment uri of the model from AIP.

  Args:
    model_endpoint_uri: Full model endpoint uri.
    credentials: The OAuth2.0 credentials to use for GCP services.

  Returns:
    String uri of the model GCS bucket.

  Raises:
    KeyError: This error will be raised if the 'deploymentUri' key is
      missing from the returned version information.
  """
  response = http_utils.make_get_request_to_ai_platform(model_endpoint_uri,
                                                        credentials)

  if 'deploymentUri' not in response:
    raise KeyError('There is no deploymentUri information in this version')

  return response['deploymentUri']