Extracting Ns._create_task() and creating unit test
[osm/RO.git] / NG-RO / osm_ng_ro / tests / test_ns.py
1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
3 #
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
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
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
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
17
18 import unittest
19
20 from osm_ng_ro.ns import Ns
21
22
23 __author__ = "Eduardo Sousa"
24 __date__ = "$19-NOV-2021 00:00:00$"
25
26
27 class TestNs(unittest.TestCase):
28 def setUp(self):
29 pass
30
31 def test__create_task(self):
32 expected_result = {
33 "target_id": "vim_openstack_1",
34 "action_id": "123456",
35 "nsr_id": "654321",
36 "task_id": "123456:1",
37 "status": "SCHEDULED",
38 "action": "CREATE",
39 "item": "test_item",
40 "target_record": "test_target_record",
41 "target_record_id": "test_target_record_id",
42 # values coming from extra_dict
43 "params": "test_params",
44 "find_params": "test_find_params",
45 "depends_on": "test_depends_on",
46 }
47 deployment_info = {
48 "action_id": "123456",
49 "nsr_id": "654321",
50 "task_index": 1,
51 }
52
53 task = Ns._create_task(
54 deployment_info=deployment_info,
55 target_id="vim_openstack_1",
56 item="test_item",
57 action="CREATE",
58 target_record="test_target_record",
59 target_record_id="test_target_record_id",
60 extra_dict={
61 "params": "test_params",
62 "find_params": "test_find_params",
63 "depends_on": "test_depends_on",
64 },
65 )
66
67 self.assertEqual(deployment_info.get("task_index"), 2)
68 self.assertDictEqual(task, expected_result)