Move InMemoryConfigStorage to a separate file

This commit is contained in:
Rafa de la Torre 2016-10-03 13:12:49 +02:00
parent 86ab3abc53
commit 3361960cfc
5 changed files with 25 additions and 24 deletions

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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):

View File

@ -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