Move InMemoryConfigStorage to a separate file
This commit is contained in:
parent
86ab3abc53
commit
3361960cfc
@ -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
|
@ -13,18 +13,6 @@ class InDbServerConfigStorage(ConfigStorageInterface):
|
|||||||
else:
|
else:
|
||||||
return None
|
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):
|
class NullConfigStorage(ConfigStorageInterface):
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
|
@ -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
|
@ -1,6 +1,6 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from cartodb_services.refactor.storage.redis_config import *
|
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
|
from cartodb_services.refactor.config.exceptions import ConfigException
|
||||||
|
|
||||||
class TestRedisConnectionConfig(TestCase):
|
class TestRedisConnectionConfig(TestCase):
|
||||||
|
@ -29,14 +29,3 @@ class TestInDbServerConfigStorage(TestCase):
|
|||||||
server_config = InDbServerConfigStorage()
|
server_config = InDbServerConfigStorage()
|
||||||
assert server_config.get('server_conf') == {'environment': 'testing'}
|
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)
|
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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user