From 929e293a479dea3059bfca152b93d7740348fc39 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Mon, 11 Oct 2021 10:41:40 -0700 Subject: [PATCH] fix: exception thrown when grpc is disabled (#190) --- google/cloud/error_reporting/_logging.py | 4 ++-- tests/system/test_system.py | 7 +++++++ tests/unit/test__logging.py | 10 +++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/google/cloud/error_reporting/_logging.py b/google/cloud/error_reporting/_logging.py index 5e83d148..c7d1d909 100644 --- a/google/cloud/error_reporting/_logging.py +++ b/google/cloud/error_reporting/_logging.py @@ -70,8 +70,8 @@ def __init__( client_options=None, ): self.logging_client = google.cloud.logging.Client( - project, - credentials, + project=project, + credentials=credentials, _http=_http, client_info=client_info, client_options=client_options, diff --git a/tests/system/test_system.py b/tests/system/test_system.py index 28125c6a..4565a358 100644 --- a/tests/system/test_system.py +++ b/tests/system/test_system.py @@ -15,6 +15,7 @@ import functools import operator import unittest +import mock from google.cloud import error_reporting import google.cloud.errorreporting_v1beta1 @@ -127,3 +128,9 @@ def test_report_exception(self): error_count = wrapped_get_count(class_name, Config.CLIENT) self.assertEqual(error_count, 1) + + def test_report_exception_no_grpc(self): + with mock.patch.dict( + "os.environ", {"GOOGLE_CLOUD_DISABLE_GRPC": "true"}, clear=True + ): + self.test_report_exception() diff --git a/tests/unit/test__logging.py b/tests/unit/test__logging.py index 772b5229..c5b1cc32 100644 --- a/tests/unit/test__logging.py +++ b/tests/unit/test__logging.py @@ -40,7 +40,11 @@ def test_ctor_defaults(self, mocked_cls): self.assertIs(logging_api.logging_client, mocked_cls.return_value) mocked_cls.assert_called_once_with( - self.PROJECT, credentials, _http=None, client_info=None, client_options=None + project=self.PROJECT, + credentials=credentials, + _http=None, + client_info=None, + client_options=None, ) @mock.patch("google.cloud.logging.Client") @@ -60,8 +64,8 @@ def test_ctor_explicit(self, mocked_cls): self.assertIs(logging_api.logging_client, mocked_cls.return_value) mocked_cls.assert_called_once_with( - self.PROJECT, - credentials, + project=self.PROJECT, + credentials=credentials, _http=http, client_info=client_info, client_options=client_options,