2 # -*- coding: utf-8 -*-
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
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 __author__
= "Alfonso Tierno, alfonso.tiernosepulveda@telefonica.com"
18 __date__
= "2020-06-17"
21 from unittest
import TestCase
23 # from unittest.mock import Mock
24 # from osm_common import dbbase, fsbase, msgbase
25 from osm_nbi
.base_topic
import BaseTopic
, EngineException
28 class Test_BaseTopic(TestCase
):
31 cls
.test_name
= "test-base-topic"
34 def tearDownClass(cls
):
39 # self.db = Mock(dbbase.DbBase())
40 # self.fs = Mock(fsbase.FsBase())
41 # self.msg = Mock(msgbase.MsgBase())
42 # self.auth = Mock(authconn.Authconn(None, None, None))
44 def test_update_input_with_kwargs(self
):
47 # (descriptor content, kwargs, expected descriptor (None=fails), message)
49 {"a": {"none": None}},
51 {"a": {"none": None, "b": {"num": "v"}}},
55 {"a": {"none": None}},
57 {"a": {"none": {"num": "v"}}},
58 "create dict over none",
61 {"a": {"b": {"num": 4}}},
63 {"a": {"b": {"num": "v"}}},
67 {"a": {"b": {"num": 4}}},
69 {"a": {"b": {"num": {"c": {"d": "v"}}}}},
70 "create dict over number",
73 {"a": {"b": {"num": 4}}},
76 "replace dict with a string",
79 {"a": {"b": {"num": 4}}},
82 "replace dict with None",
85 {"a": [{"b": {"num": 4}}]},
88 "create dict over list should fail",
91 {"a": [{"b": {"num": 4}}]},
93 {"a": [{"b": {"num": "v"}}]},
97 {"a": [{"b": {"num": 4}}]},
99 {"a": [{"b": {"num": 4}}, None, None, {"b": {"num": "v"}}]},
102 ({"a": [[4]]}, {"a.0.0": "v"}, {"a": [["v"]]}, "set nested list"),
106 {"a": [[4, None, "v"]]},
107 "expand nested list",
112 {"a": [[4], None, {"2": "v"}]},
113 "expand list and add number key",
115 ({"a": None}, {"b.c": "v"}, {"a": None, "b": {"c": "v"}}, "expand at root"),
117 for desc
, kwargs
, expected
, message
in test_set
:
120 EngineException
, BaseTopic
._update
_input
_with
_kwargs
, desc
, kwargs
123 BaseTopic
._update
_input
_with
_kwargs
(desc
, kwargs
)
124 self
.assertEqual(desc
, expected
, message
)
127 if __name__
== "__main__":