From 5005572f89eb0f2bac761360b2f9306de7aed1a3 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Fri, 6 Oct 2017 15:18:51 +0200 Subject: [PATCH] Add tests for GoogleMapsClientFactory --- .../test/test_google_client_factory.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 server/lib/python/cartodb_services/test/test_google_client_factory.py 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 new file mode 100644 index 0000000..b5b3121 --- /dev/null +++ b/server/lib/python/cartodb_services/test/test_google_client_factory.py @@ -0,0 +1,47 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- + +import unittest +import base64 + +from cartodb_services.google.client_factory import GoogleMapsClientFactory + +class GoogleMapsClientFactoryTestCase(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + # reset client cache + GoogleMapsClientFactory.clients = {} + + def test_consecutive_calls_with_same_params_return_same_client(self): + id = 'any_id' + key = base64.b64encode('any_key') + client1 = GoogleMapsClientFactory.get(id, key) + client2 = GoogleMapsClientFactory.get(id, key) + self.assertEqual(client1, client2) + + def test_consecutive_calls_with_different_key_return_different_clients(self): + """ + This requirement is important for security reasons as well as not to + cache a wrong key accidentally. + """ + id = 'any_id' + key1 = base64.b64encode('any_key') + key2 = base64.b64encode('another_key') + client1 = GoogleMapsClientFactory.get(id, key1) + client2 = GoogleMapsClientFactory.get(id, key2) + self.assertNotEqual(client1, client2) + + def test_consecutive_calls_with_different_ids_return_different_clients(self): + """ + This requirement is important for security reasons as well as not to + cache a wrong key accidentally. + """ + id1 = 'any_id' + id2 = 'another_id' + key = base64.b64encode('any_key') + client1 = GoogleMapsClientFactory.get(id1, key) + client2 = GoogleMapsClientFactory.get(id2, key) + self.assertNotEqual(client1, client2)