@@ -217,31 +217,35 @@ def __call__(self, req):
217217
218218 self .assertEqual (2 , len (responses .calls ))
219219
220- def test_channel_with_api_key (self ):
220+ def test_channel_without_client_id (self ):
221221 with self .assertRaises (ValueError ):
222222 client = googlemaps .Client (key = "AIzaasdf" , channel = "mychannel" )
223223
224224 def test_invalid_channel (self ):
225+ # Cf. limitations here:
226+ # https://developers.google.com/maps/premium/reports
227+ # /usage-reports#channels
225228 with self .assertRaises (ValueError ):
226- client = googlemaps .Client (client_id = "foo" , client_secret = "a2V5" , channel = "auieauie$? " )
227-
228- @responses .activate
229- def test_channel_with_client_id (self ):
230- responses .add (responses .GET ,
231- "https://maps.googleapis.com/maps/api/geocode/json" ,
232- body = '{"status":"OK","results":[]}' ,
233- status = 200 ,
234- content_type = "application/json" )
235-
236- client = googlemaps .Client (client_id = "foo" , client_secret = "a2V5" , channel = "MyChannel_1" )
237- client .geocode ("Sesame St." )
238-
239- self .assertEqual (1 , len (responses .calls ))
240-
241- # Check ordering of parameters.
242- self .assertIn ("address=Sesame+St.&channel=MyChannel_1&client=foo&signature" ,
243- responses .calls [0 ].request .url )
244- self .assertURLEqual ("https://maps.googleapis.com/maps/api/geocode/json?"
245- "address=Sesame+St.&channel=MyChannel_1&client=foo&"
246- "signature=5s4Hw2AitGZlkipugXkjPuxhmME=" ,
247- responses .calls [0 ].request .url )
229+ client = googlemaps .Client (client_id = "foo" , client_secret = "a2V5" ,
230+ channel = "auieauie$? " )
231+
232+ def test_auth_url_with_channel (self ):
233+ client = googlemaps .Client (key = "AIzaasdf" ,
234+ client_id = "foo" ,
235+ client_secret = "a2V5" ,
236+ channel = "MyChannel_1" )
237+
238+ # Check ordering of parameters + signature.
239+ auth_url = client ._generate_auth_url ("/test" ,
240+ {"param" : "param" },
241+ accepts_clientid = True )
242+ self .assertEqual (auth_url , "/test?param=param"
243+ "&channel=MyChannel_1"
244+ "&client=foo"
245+ "&signature=OH18GuQto_mEpxj99UimKskvo4k=" )
246+
247+ # Check if added to requests to API with accepts_clientid=False
248+ auth_url = client ._generate_auth_url ("/test" ,
249+ {"param" : "param" },
250+ accepts_clientid = False )
251+ self .assertEqual (auth_url , "/test?param=param&key=AIzaasdf" )
0 commit comments