From 3361960cfc241b4f749ce7ad1aa43c9f043fec58 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Mon, 3 Oct 2016 13:12:49 +0200 Subject: [PATCH] Move InMemoryConfigStorage to a separate file --- .../cartodb_services/refactor/storage/mem_config.py | 12 ++++++++++++ .../refactor/storage/server_config.py | 12 ------------ .../test/refactor/storage/test_mem_config.py | 12 ++++++++++++ .../test/refactor/storage/test_redis_config.py | 2 +- .../test/refactor/storage/test_server_config.py | 11 ----------- 5 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 server/lib/python/cartodb_services/cartodb_services/refactor/storage/mem_config.py create mode 100644 server/lib/python/cartodb_services/test/refactor/storage/test_mem_config.py diff --git a/server/lib/python/cartodb_services/cartodb_services/refactor/storage/mem_config.py b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/mem_config.py new file mode 100644 index 0000000..01d3981 --- /dev/null +++ b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/mem_config.py @@ -0,0 +1,12 @@ +from interfaces import ConfigStorageInterface + +class InMemoryConfigStorage(ConfigStorageInterface): + + def __init__(self, config_hash={}): + self._config_hash = config_hash + + def get(self, key): + try: + return self._config_hash[key] + except KeyError: + return None diff --git a/server/lib/python/cartodb_services/cartodb_services/refactor/storage/server_config.py b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/server_config.py index 7a65946..e02259b 100644 --- a/server/lib/python/cartodb_services/cartodb_services/refactor/storage/server_config.py +++ b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/server_config.py @@ -13,18 +13,6 @@ class InDbServerConfigStorage(ConfigStorageInterface): else: return None - -class InMemoryConfigStorage(ConfigStorageInterface): - - def __init__(self, config_hash={}): - self._config_hash = config_hash - - def get(self, key): - try: - return self._config_hash[key] - except KeyError: - return None - class NullConfigStorage(ConfigStorageInterface): def get(self, key): diff --git a/server/lib/python/cartodb_services/test/refactor/storage/test_mem_config.py b/server/lib/python/cartodb_services/test/refactor/storage/test_mem_config.py new file mode 100644 index 0000000..3caf3e3 --- /dev/null +++ b/server/lib/python/cartodb_services/test/refactor/storage/test_mem_config.py @@ -0,0 +1,12 @@ +from unittest import TestCase +from cartodb_services.refactor.storage.mem_config import InMemoryConfigStorage + +class TestInMemoryConfigStorage(TestCase): + + def test_can_provide_values_from_hash(self): + server_config = InMemoryConfigStorage({'any_key': 'any_value'}) + assert server_config.get('any_key') == 'any_value' + + def test_gets_none_if_cannot_retrieve_key(self): + server_config = InMemoryConfigStorage() + assert server_config.get('any_non_existing_key') == None diff --git a/server/lib/python/cartodb_services/test/refactor/storage/test_redis_config.py b/server/lib/python/cartodb_services/test/refactor/storage/test_redis_config.py index 292874e..a99956e 100644 --- a/server/lib/python/cartodb_services/test/refactor/storage/test_redis_config.py +++ b/server/lib/python/cartodb_services/test/refactor/storage/test_redis_config.py @@ -1,6 +1,6 @@ from unittest import TestCase from cartodb_services.refactor.storage.redis_config import * -from cartodb_services.refactor.storage.server_config import InMemoryConfigStorage +from cartodb_services.refactor.storage.mem_config import InMemoryConfigStorage from cartodb_services.refactor.config.exceptions import ConfigException class TestRedisConnectionConfig(TestCase): diff --git a/server/lib/python/cartodb_services/test/refactor/storage/test_server_config.py b/server/lib/python/cartodb_services/test/refactor/storage/test_server_config.py index 4e3d27c..ece3c6b 100644 --- a/server/lib/python/cartodb_services/test/refactor/storage/test_server_config.py +++ b/server/lib/python/cartodb_services/test/refactor/storage/test_server_config.py @@ -29,14 +29,3 @@ class TestInDbServerConfigStorage(TestCase): server_config = InDbServerConfigStorage() assert server_config.get('server_conf') == {'environment': 'testing'} self.plpy_mock.execute.assert_called_once_with("SELECT cdb_dataservices_server.cdb_conf_getconf('server_conf') as conf", 1) - - -class TestInMemoryConfigStorage(TestCase): - - def test_can_provide_values_from_hash(self): - server_config = InMemoryConfigStorage({'any_key': 'any_value'}) - assert server_config.get('any_key') == 'any_value' - - def test_gets_none_if_cannot_retrieve_key(self): - server_config = InMemoryConfigStorage() - assert server_config.get('any_non_existing_key') == None