@@ -191,6 +191,53 @@ def test_ctor_w_client_options_object(self):
191191 self .assertEqual (client ._connection .API_BASE_URL , api_endpoint )
192192 self .assertEqual (client .api_endpoint , api_endpoint )
193193
194+ def test_ctor_w_api_key (self ):
195+ from google .auth .api_key import Credentials
196+
197+ PROJECT = "PROJECT"
198+ api_key = "my_api_key"
199+
200+ client = self ._make_one (project = PROJECT , api_key = api_key )
201+
202+ self .assertEqual (
203+ client ._connection .API_BASE_URL , client ._connection .DEFAULT_API_ENDPOINT
204+ )
205+ self .assertIsInstance (client ._credentials , Credentials )
206+ self .assertEqual (client ._credentials .token , api_key )
207+
208+ def test_ctor_w_api_key_and_client_options (self ):
209+ from google .auth .api_key import Credentials
210+ from google .api_core .client_options import ClientOptions
211+
212+ PROJECT = "PROJECT"
213+ api_key = "my_api_key"
214+ api_endpoint = "https://www.foo-googleapis.com"
215+ client_options = ClientOptions (api_endpoint = api_endpoint )
216+
217+ client = self ._make_one (
218+ project = PROJECT , client_options = client_options , api_key = api_key
219+ )
220+
221+ self .assertEqual (client ._connection .API_BASE_URL , api_endpoint )
222+ self .assertIsInstance (client ._credentials , Credentials )
223+ self .assertEqual (client ._credentials .token , api_key )
224+
225+ def test_ctor_w_api_key_and_client_dict (self ):
226+ from google .auth .api_key import Credentials
227+
228+ PROJECT = "PROJECT"
229+ api_key = "my_api_key"
230+ api_endpoint = "https://www.foo-googleapis.com"
231+ client_options = {"api_endpoint" : api_endpoint }
232+
233+ client = self ._make_one (
234+ project = PROJECT , client_options = client_options , api_key = api_key
235+ )
236+
237+ self .assertEqual (client ._connection .API_BASE_URL , api_endpoint )
238+ self .assertIsInstance (client ._credentials , Credentials )
239+ self .assertEqual (client ._credentials .token , api_key )
240+
194241 def test_ctor_w_universe_domain_and_matched_credentials (self ):
195242 PROJECT = "PROJECT"
196243 universe_domain = "example.com"
0 commit comments