  def testCreateInstanceFromRequestError(
      self, mock_gce_api):
    """Test creating compute instance via providing arguments."""
    instances = mock_gce_api.return_value.instances
    mock_insert = instances.return_value.insert

    mock_insert.return_value.execute.side_effect = HttpError(
        resp=mock.Mock(status=409), content=b'An instance with the name')
    with self.assertRaises(errors.ResourceAlreadyExistsError) as context:
      _ = gcp_mocks.FAKE_ANALYSIS_PROJECT.compute.CreateInstanceFromRequest(
        {'name': gcp_mocks.FAKE_INSTANCE.name}, 'us-central1-a')
    msg = (
            'An instance with the name {0:s} already exists '
            'in project {1:s}').format(
                gcp_mocks.FAKE_INSTANCE.name,
                gcp_mocks.FAKE_ANALYSIS_PROJECT.project_id)
    self.assertIn(msg, str(context.exception))

    mock_insert.return_value.execute.side_effect = HttpError(
        resp=mock.Mock(status=400), content=b'Error while creating instance')
    with self.assertRaises(errors.ResourceCreationError) as context:
      _ = gcp_mocks.FAKE_ANALYSIS_PROJECT.compute.CreateInstanceFromRequest(
        {'name': gcp_mocks.FAKE_INSTANCE.name}, 'us-central1-a')
    msg = 'Error while creating instance {0:s}'.format(
        gcp_mocks.FAKE_INSTANCE.name)
    self.assertIn(msg, str(context.exception))
Test creating compute instance via providing arguments.
tests/providers/gcp/internal/test_compute.py