diff --git a/server/lib/python/cartodb_services/test/test_google_client_factory.py b/server/lib/python/cartodb_services/test/test_google_client_factory.py index f09da5a..7fd001b 100644 --- a/server/lib/python/cartodb_services/test/test_google_client_factory.py +++ b/server/lib/python/cartodb_services/test/test_google_client_factory.py @@ -18,10 +18,10 @@ class GoogleMapsClientFactoryTestCase(unittest.TestCase): GoogleMapsClientFactory.clients = {} def test_consecutive_calls_with_same_params_return_same_client(self): - id = 'any_id' + client_id = 'any_id' key = base64.b64encode('any_key') - client1 = GoogleMapsClientFactory.get(id, key) - client2 = GoogleMapsClientFactory.get(id, key) + client1 = GoogleMapsClientFactory.get(client_id, key) + client2 = GoogleMapsClientFactory.get(client_id, key) self.assertEqual(client1, client2) def test_consecutive_calls_with_different_key_return_different_clients(self): @@ -29,11 +29,11 @@ class GoogleMapsClientFactoryTestCase(unittest.TestCase): This requirement is important for security reasons as well as not to cache a wrong key accidentally. """ - id = 'any_id' + client_id = 'any_id' key1 = base64.b64encode('any_key') key2 = base64.b64encode('another_key') - client1 = GoogleMapsClientFactory.get(id, key1) - client2 = GoogleMapsClientFactory.get(id, key2) + client1 = GoogleMapsClientFactory.get(client_id, key1) + client2 = GoogleMapsClientFactory.get(client_id, key2) self.assertNotEqual(client1, client2) def test_consecutive_calls_with_different_ids_return_different_clients(self): @@ -59,3 +59,11 @@ class GoogleMapsClientFactoryTestCase(unittest.TestCase): def test_credentials_with_underscores_can_be_valid(self): client = GoogleMapsClientFactory.get('yet_another_dummy_client_id', 'Ola_k_ase___') self.assertIsInstance(client, googlemaps.Client) + + def test_invalid_credentials(self): + with self.assertRaises(InvalidGoogleCredentials): + GoogleMapsClientFactory.get('dummy_client_id', 'lalala') + + def test_credentials_with_channel(self): + client = GoogleMapsClientFactory.get('yet_another_dummy_client_id', 'Ola_k_ase___', 'channel') + self.assertIsInstance(client, googlemaps.Client) diff --git a/server/lib/python/cartodb_services/test/test_googlegeocoder.py b/server/lib/python/cartodb_services/test/test_googlegeocoder.py index ecbaa7b..bf56a60 100644 --- a/server/lib/python/cartodb_services/test/test_googlegeocoder.py +++ b/server/lib/python/cartodb_services/test/test_googlegeocoder.py @@ -118,3 +118,18 @@ class GoogleGeocoderTestCase(unittest.TestCase): searchtext='Calle Eloy Gonzalo 27', city='Madrid', country='EspaƱa') + + def test_client_data_extraction(self, req_mock): + client_id, channel = self.geocoder.parse_client_id('dummy_client_id') + self.assertEqual(client_id, 'dummy_client_id') + self.assertEqual(channel, None) + + def test_client_data_extraction_with_client_parameter(self, req_mock): + client_id, channel = self.geocoder.parse_client_id('client=gme-test') + self.assertEqual(client_id, 'gme-test') + self.assertEqual(channel, None) + + def test_client_data_extraction_with_client_and_channel_parameter(self, req_mock): + client_id, channel = self.geocoder.parse_client_id('client=gme-test&channel=testchannel') + self.assertEqual(client_id, 'gme-test') + self.assertEqual(channel, 'testchannel')