1717import mock
1818
1919
20+ def _make_credentials ():
21+ import google .auth .credentials
22+ return mock .Mock (spec = google .auth .credentials .Credentials )
23+
24+
2025class Test_ClientFactoryMixin (unittest .TestCase ):
2126
2227 @staticmethod
@@ -52,7 +57,7 @@ def test_ctor_defaults(self):
5257 from google .cloud ._testing import _Monkey
5358 from google .cloud import client
5459
55- CREDENTIALS = object ()
60+ CREDENTIALS = _make_credentials ()
5661 FUNC_CALLS = []
5762
5863 def mock_get_credentials ():
@@ -67,20 +72,27 @@ def mock_get_credentials():
6772 self .assertEqual (FUNC_CALLS , ['get_credentials' ])
6873
6974 def test_ctor_explicit (self ):
70- CREDENTIALS = object ()
75+ CREDENTIALS = _make_credentials ()
7176 HTTP = object ()
7277 client_obj = self ._make_one (credentials = CREDENTIALS , http = HTTP )
7378
7479 self .assertIsInstance (client_obj ._connection , _MockConnection )
7580 self .assertIs (client_obj ._connection .credentials , CREDENTIALS )
7681 self .assertIs (client_obj ._connection .http , HTTP )
7782
83+ def test_ctor_bad_credentials (self ):
84+ CREDENTIALS = object ()
85+
86+ with self .assertRaises (ValueError ):
87+ self ._make_one (credentials = CREDENTIALS )
88+
7889 def test_from_service_account_json (self ):
7990 KLASS = self ._get_target_class ()
8091
8192 constructor_patch = mock .patch (
8293 'google.oauth2.service_account.Credentials.'
83- 'from_service_account_file' )
94+ 'from_service_account_file' ,
95+ return_value = _make_credentials ())
8496
8597 with constructor_patch as constructor :
8698 client_obj = KLASS .from_service_account_json (
@@ -122,7 +134,7 @@ def test_ctor_defaults(self):
122134 from google .cloud import client
123135
124136 PROJECT = 'PROJECT'
125- CREDENTIALS = object ()
137+ CREDENTIALS = _make_credentials ()
126138 FUNC_CALLS = []
127139
128140 def mock_determine_proj (project ):
@@ -160,7 +172,7 @@ def mock_determine_proj(project):
160172 self .assertEqual (FUNC_CALLS , [(None , '_determine_default_project' )])
161173
162174 def test_ctor_w_invalid_project (self ):
163- CREDENTIALS = object ()
175+ CREDENTIALS = _make_credentials ()
164176 HTTP = object ()
165177 with self .assertRaises (ValueError ):
166178 self ._make_one (project = object (), credentials = CREDENTIALS ,
@@ -169,7 +181,7 @@ def test_ctor_w_invalid_project(self):
169181 def _explicit_ctor_helper (self , project ):
170182 import six
171183
172- CREDENTIALS = object ()
184+ CREDENTIALS = _make_credentials ()
173185 HTTP = object ()
174186
175187 client_obj = self ._make_one (project = project , credentials = CREDENTIALS ,
0 commit comments