@@ -53,26 +53,72 @@ def _get_report_payload(self, error_api):
5353 return positional [0 ]
5454
5555 @mock .patch ("google.cloud.client._determine_default_project" )
56- def test_ctor_default (self , default_mock ):
56+ def test_ctor_defaults (self , default_mock ):
57+ from google .api_core .client_info import ClientInfo
58+
5759 credentials = _make_credentials ()
5860 default_mock .return_value = "foo"
5961 client = self ._make_one (credentials = credentials )
6062 self .assertEqual (client .service , client .DEFAULT_SERVICE )
6163 self .assertEqual (client .version , None )
64+ self .assertIsInstance (client ._client_info , ClientInfo )
6265 default_mock .assert_called_once_with (None )
6366
64- def test_ctor_params (self ):
67+ def test_ctor_explicit (self ):
6568 credentials = _make_credentials ()
69+ client_info = mock .Mock ()
6670 client = self ._make_one (
6771 project = self .PROJECT ,
6872 credentials = credentials ,
6973 service = self .SERVICE ,
7074 version = self .VERSION ,
75+ client_info = client_info ,
7176 )
7277 self .assertEqual (client .service , self .SERVICE )
7378 self .assertEqual (client .version , self .VERSION )
79+ self .assertIs (client ._client_info , client_info )
80+
81+ def test_report_errors_api_already (self ):
82+ credentials = _make_credentials ()
83+ client = self ._make_one (project = self .PROJECT , credentials = credentials )
84+ client ._report_errors_api = already = mock .Mock ()
85+ self .assertIs (client .report_errors_api , already )
86+
87+ def test_report_errors_api_wo_grpc (self ):
88+ credentials = _make_credentials ()
89+ client_info = mock .Mock ()
90+ http = mock .Mock ()
91+ client = self ._make_one (
92+ project = self .PROJECT ,
93+ credentials = credentials ,
94+ client_info = client_info ,
95+ _http = http ,
96+ _use_grpc = False ,
97+ )
98+ patch = mock .patch (
99+ "google.cloud.error_reporting.client._ErrorReportingLoggingAPI"
100+ )
101+
102+ with patch as patched :
103+ api = client .report_errors_api
104+
105+ self .assertIs (api , patched .return_value )
106+ patched .assert_called_once_with (self .PROJECT , credentials , http , client_info )
107+
108+ def test_report_errors_api_w_grpc (self ):
109+ credentials = _make_credentials ()
110+ client = self ._make_one (
111+ project = self .PROJECT , credentials = credentials , _use_grpc = True
112+ )
113+ patch = mock .patch ("google.cloud.error_reporting.client.make_report_error_api" )
114+
115+ with patch as patched :
116+ api = client .report_errors_api
117+
118+ self .assertIs (api , patched .return_value )
119+ patched .assert_called_once_with (client )
74120
75- def test_report_exception_with_gax (self ):
121+ def test_report_exception_with_grpc (self ):
76122 credentials = _make_credentials ()
77123 client = self ._make_one (project = self .PROJECT , credentials = credentials )
78124
@@ -89,7 +135,7 @@ def test_report_exception_with_gax(self):
89135 self .assertIn ("test_report" , payload ["message" ])
90136 self .assertIn ("test_client.py" , payload ["message" ])
91137
92- def test_report_exception_wo_gax (self ):
138+ def test_report_exception_wo_grpc (self ):
93139 credentials = _make_credentials ()
94140 client = self ._make_one (
95141 project = self .PROJECT , credentials = credentials , _use_grpc = False
0 commit comments