Added tests for the client/channel part of google
This commit is contained in:
parent
544e0fa763
commit
07f00cc0ae
@ -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)
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user