1 # Copyright 2020 Canonical Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from unittest
import TestCase
16 from unittest
.mock
import patch
19 from n2vc
.config
import EnvironConfig
, ModelConfig
, MODEL_CONFIG_KEYS
22 def generate_os_environ_dict(config
, prefix
):
23 return {f
"{prefix}{k.upper()}": v
for k
, v
in config
.items()}
26 class TestEnvironConfig(TestCase
):
28 self
.config
= {"host": "1.2.3.4", "port": "17070", "k8s_cloud": "k8s"}
30 @patch("os.environ.items")
31 def test_environ_config_lcm(self
, mock_environ_items
):
32 envs
= generate_os_environ_dict(self
.config
, "OSMLCM_VCA_")
33 envs
["not_valid_env"] = "something"
34 mock_environ_items
.return_value
= envs
.items()
35 config
= EnvironConfig()
36 self
.assertEqual(config
, self
.config
)
38 @patch("os.environ.items")
39 def test_environ_config_mon(self
, mock_environ_items
):
40 envs
= generate_os_environ_dict(self
.config
, "OSMMON_VCA_")
41 envs
["not_valid_env"] = "something"
42 mock_environ_items
.return_value
= envs
.items()
43 config
= EnvironConfig()
44 self
.assertEqual(config
, self
.config
)
47 class TestModelConfig(TestCase
):
50 f
'model_config_{model_key.replace("-", "_")}': "somevalue"
51 for model_key
in MODEL_CONFIG_KEYS
53 self
.config
["model_config_invalid"] = "something"
54 self
.model_config
= {model_key
: "somevalue" for model_key
in MODEL_CONFIG_KEYS
}
56 def test_model_config(self
):
57 model_config
= ModelConfig(self
.config
)
58 self
.assertEqual(model_config
, self
.model_config
)