3fa617b902757aaf33ce4a5a9a9309caaac6f843
[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 from unittest.mock import patch, Mock
20
21 from osm_ng_ro.ns import Ns
22
23
24 __author__ = "Eduardo Sousa"
25 __date__ = "$19-NOV-2021 00:00:00$"
26
27
28 class TestNs(unittest.TestCase):
29 def setUp(self):
30 pass
31
32 def test__create_task(self):
33 expected_result = {
34 "target_id": "vim_openstack_1",
35 "action_id": "123456",
36 "nsr_id": "654321",
37 "task_id": "123456:1",
38 "status": "SCHEDULED",
39 "action": "CREATE",
40 "item": "test_item",
41 "target_record": "test_target_record",
42 "target_record_id": "test_target_record_id",
43 # values coming from extra_dict
44 "params": "test_params",
45 "find_params": "test_find_params",
46 "depends_on": "test_depends_on",
47 }
48 deployment_info = {
49 "action_id": "123456",
50 "nsr_id": "654321",
51 "task_index": 1,
52 }
53
54 task = Ns._create_task(
55 deployment_info=deployment_info,
56 target_id="vim_openstack_1",
57 item="test_item",
58 action="CREATE",
59 target_record="test_target_record",
60 target_record_id="test_target_record_id",
61 extra_dict={
62 "params": "test_params",
63 "find_params": "test_find_params",
64 "depends_on": "test_depends_on",
65 },
66 )
67
68 self.assertEqual(deployment_info.get("task_index"), 2)
69 self.assertDictEqual(task, expected_result)
70
71 @patch("osm_ng_ro.ns.time")
72 def test__create_ro_task(self, mock_time: Mock):
73 now = 1637324838.994551
74 mock_time.return_value = now
75 task = {
76 "target_id": "vim_openstack_1",
77 "action_id": "123456",
78 "nsr_id": "654321",
79 "task_id": "123456:1",
80 "status": "SCHEDULED",
81 "action": "CREATE",
82 "item": "test_item",
83 "target_record": "test_target_record",
84 "target_record_id": "test_target_record_id",
85 # values coming from extra_dict
86 "params": "test_params",
87 "find_params": "test_find_params",
88 "depends_on": "test_depends_on",
89 }
90 expected_result = {
91 "_id": "123456:1",
92 "locked_by": None,
93 "locked_at": 0.0,
94 "target_id": "vim_openstack_1",
95 "vim_info": {
96 "created": False,
97 "created_items": None,
98 "vim_id": None,
99 "vim_name": None,
100 "vim_status": None,
101 "vim_details": None,
102 "refresh_at": None,
103 },
104 "modified_at": now,
105 "created_at": now,
106 "to_check_at": now,
107 "tasks": [task],
108 }
109
110 ro_task = Ns._create_ro_task(
111 target_id="vim_openstack_1",
112 task=task,
113 )
114
115 self.assertDictEqual(ro_task, expected_result)