1 # Copyright (c) 2019 AT&T Intellectual Property.
2 # Copyright (c) 2018-2019 Nokia.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 # This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 # platform project (RICP).
23 from ricsdl.configuration import _Configuration
27 def config_fixture(request, monkeypatch):
28 monkeypatch.setenv('DBAAS_SERVICE_HOST', '10.20.30.40')
29 monkeypatch.setenv('DBAAS_SERVICE_PORT', '10000')
30 monkeypatch.setenv('DBAAS_SERVICE_SENTINEL_PORT', '11000')
31 monkeypatch.setenv('DBAAS_MASTER_NAME', 'my-master')
32 request.cls.config = _Configuration()
33 request.cls.config._read_configuration()
37 def config_missing_fixture(request, monkeypatch):
38 monkeypatch.delenv('DBAAS_SERVICE_HOST', raising=False)
39 monkeypatch.delenv('DBAAS_SERVICE_PORT', raising=False)
40 monkeypatch.delenv('DBAAS_SERVICE_SENTINEL_PORT', raising=False)
41 monkeypatch.delenv('DBAAS_MASTER_NAME', raising=False)
42 request.cls.config = _Configuration()
43 request.cls.config._read_configuration()
46 class TestConfiguration:
47 def test_get_params_function_returns_read_configuration(self, config_fixture):
48 expected_config = _Configuration.Params(db_host='10.20.30.40', db_port='10000',
49 db_sentinel_port='11000',
50 db_sentinel_master_name='my-master')
51 assert expected_config == self.config.get_params()
53 def test_get_params_function_can_return_empty_configuration(self, config_missing_fixture):
54 expected_config = _Configuration.Params(db_host=None, db_port=None,
55 db_sentinel_port=None,
56 db_sentinel_master_name=None)
57 assert expected_config == self.config.get_params()
59 def test_configuration_object_string_representation(self, config_fixture):
60 expected_config_info = {'DB host': '10.20.30.40',
62 'DB master sentinel': 'my-master',
63 'DB sentinel port': '11000'}
64 assert str(self.config) == str(expected_config_info)
66 def test_configuration_object_string_representation_if_no_config(self, config_missing_fixture):
67 expected_config_info = {'DB host': None,
69 'DB master sentinel': None,
70 'DB sentinel port': None}
71 assert str(self.config) == str(expected_config_info)