import pytest
from ricsdl.configuration import _Configuration
+from ricsdl.configuration import DbBackendType
@pytest.fixture()
monkeypatch.setenv('DBAAS_SERVICE_PORT', '10000')
monkeypatch.setenv('DBAAS_SERVICE_SENTINEL_PORT', '11000')
monkeypatch.setenv('DBAAS_MASTER_NAME', 'my-master')
- request.cls.config = _Configuration()
- request.cls.config._read_configuration()
+ request.cls.config = _Configuration(fake_db_backend=None)
@pytest.fixture
-def config_missing_fixture(request, monkeypatch):
+def fake_db_config_fixture(request, monkeypatch):
monkeypatch.delenv('DBAAS_SERVICE_HOST', raising=False)
monkeypatch.delenv('DBAAS_SERVICE_PORT', raising=False)
monkeypatch.delenv('DBAAS_SERVICE_SENTINEL_PORT', raising=False)
monkeypatch.delenv('DBAAS_MASTER_NAME', raising=False)
- request.cls.config = _Configuration()
- request.cls.config._read_configuration()
+ request.cls.config = _Configuration(fake_db_backend='dict')
class TestConfiguration:
def test_get_params_function_returns_read_configuration(self, config_fixture):
expected_config = _Configuration.Params(db_host='10.20.30.40', db_port='10000',
db_sentinel_port='11000',
- db_sentinel_master_name='my-master')
+ db_sentinel_master_name='my-master',
+ db_type=DbBackendType.REDIS)
assert expected_config == self.config.get_params()
- def test_get_params_function_can_return_empty_configuration(self, config_missing_fixture):
+ def test_get_params_function_can_return_fake_db_configuration(self, fake_db_config_fixture):
expected_config = _Configuration.Params(db_host=None, db_port=None,
db_sentinel_port=None,
- db_sentinel_master_name=None)
+ db_sentinel_master_name=None,
+ db_type=DbBackendType.FAKE_DICT)
assert expected_config == self.config.get_params()
+ def test_get_params_function_can_raise_exception_if_wrong_fake_db_type(self):
+ with pytest.raises(ValueError, match=r"Configuration error"):
+ _Configuration(fake_db_backend='bad value')
+
+
def test_configuration_object_string_representation(self, config_fixture):
expected_config_info = {'DB host': '10.20.30.40',
'DB port': '10000',
'DB master sentinel': 'my-master',
- 'DB sentinel port': '11000'}
+ 'DB sentinel port': '11000',
+ 'DB type': 'REDIS'}
assert str(self.config) == str(expected_config_info)
- def test_configuration_object_string_representation_if_no_config(self, config_missing_fixture):
+ def test_configuration_object_string_representation_if_fake_db(self, fake_db_config_fixture):
expected_config_info = {'DB host': None,
'DB port': None,
'DB master sentinel': None,
- 'DB sentinel port': None}
+ 'DB sentinel port': None,
+ 'DB type': 'FAKE_DICT'}
assert str(self.config) == str(expected_config_info)