From 536294c71add74286a3f3636abb087818a45c004 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Tue, 21 Mar 2017 11:10:02 -0700 Subject: [PATCH] Use ClientWithProject superclass for error reporting. (#3168) --- .../google/cloud/error_reporting/client.py | 15 +++++---------- error_reporting/unit_tests/test_client.py | 6 +++--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/error_reporting/google/cloud/error_reporting/client.py b/error_reporting/google/cloud/error_reporting/client.py index 3f4d2ab29197..043d3faef1eb 100644 --- a/error_reporting/google/cloud/error_reporting/client.py +++ b/error_reporting/google/cloud/error_reporting/client.py @@ -23,7 +23,7 @@ except ImportError: # pragma: NO COVER _HAVE_GAX = False -from google.cloud._helpers import _determine_default_project +from google.cloud.client import ClientWithProject from google.cloud.error_reporting._logging import _ErrorReportingLoggingAPI from google.cloud.environment_vars import DISABLE_GRPC @@ -74,7 +74,7 @@ def __init__(self, method=None, url=None, self.remoteIp = remote_ip -class Client(object): +class Client(ClientWithProject): """Error Reporting client. Currently Error Reporting is done by creating a Logging client. @@ -125,13 +125,8 @@ def __init__(self, project=None, service=None, version=None, use_gax=None): - if project is None: - self._project = _determine_default_project() - else: - self._project = project - self._credentials = credentials - self._http = http - + super(Client, self).__init__(project=project, credentials=credentials, + http=http) self._report_errors_api = None self.service = service if service else self.DEFAULT_SERVICE @@ -162,7 +157,7 @@ def report_errors_api(self): self._report_errors_api = make_report_error_api(self) else: self._report_errors_api = _ErrorReportingLoggingAPI( - self._project, self._credentials, self._http) + self.project, self._credentials, self._http) return self._report_errors_api def _build_error_report(self, diff --git a/error_reporting/unit_tests/test_client.py b/error_reporting/unit_tests/test_client.py index 25c16ecb8de4..ef8999d4bf6a 100644 --- a/error_reporting/unit_tests/test_client.py +++ b/error_reporting/unit_tests/test_client.py @@ -52,14 +52,14 @@ def _get_report_payload(self, error_api): self.assertEqual(len(positional), 1) return positional[0] - @mock.patch( - 'google.cloud.error_reporting.client._determine_default_project') + @mock.patch('google.cloud.client._determine_default_project') def test_ctor_default(self, default_mock): credentials = _make_credentials() + default_mock.return_value = 'foo' client = self._make_one(credentials=credentials) self.assertEqual(client.service, client.DEFAULT_SERVICE) self.assertEqual(client.version, None) - default_mock.assert_called_once_with() + default_mock.assert_called_once_with(None) def test_ctor_params(self): credentials = _make_credentials()