2 # SPDX-License-Identifier: Apache-2.0
3 """Test OranSdnc module."""
5 from unittest import mock
6 from oransdk.sdnc.sdnc import OranSdnc
8 BASE_URL = "http://localhost:8282"
9 BASIC_AUTH = {'username': 'dcae@dcae.onap.org', 'password': 'demo123456!'}
10 HEADER = {"Accept": "application/json", "Content-Type": "application/json"}
11 def test_initialization():
12 """Class initialization test."""
14 assert isinstance(sdnc, OranSdnc)
17 @mock.patch.object(OranSdnc, 'send_message')
18 def test_get_status(mock_send_message):
19 """Test Sdnc's class method."""
21 mock_send_message.assert_called_once_with('GET',
22 'Get status of SDNC component',
23 (f"{BASE_URL}/apidoc/explorer/"))
25 @mock.patch.object(OranSdnc, 'send_message_json')
26 def test_get_odu_oru_status(mock_send_message_json):
27 """Test Sdnc's class method."""
28 OranSdnc.get_odu_oru_status("o-du", "radio21", BASIC_AUTH)
29 mock_send_message_json.assert_called_once_with('GET',
30 'Get status of Odu connectivity',
31 (f"{BASE_URL}/rests/data/network-topology:network-topology/topology=topology-netconf/node=o-du/yang-ext:mount/o-ran-sc-du-hello-world:network-function/distributed-unit-functions=o-du/radio-resource-management-policy-ratio=radio21"),
32 basic_auth=BASIC_AUTH)
33 @mock.patch.object(OranSdnc, 'send_message')
34 def test_get_devices(mock_send_message):
35 """Test Sdnc's class method."""
36 OranSdnc.get_devices("device", BASIC_AUTH)
37 mock_send_message.assert_called_with('GET', 'Get status of Device connectivity',
38 (f"{BASE_URL}/rests/data/network-topology:network-topology/topology=topology-netconf/node=device"), basic_auth=BASIC_AUTH)
39 @mock.patch.object(OranSdnc, 'send_message')
40 def test_get_events(mock_send_message):
41 """Test Sdnc's class method."""
42 OranSdnc.get_events(BASIC_AUTH, "device")
43 data = '{"input": {"filter": [ {"property": "node-id", "filtervalue": "device"}],"sortorder":[{"property": "timestamp","sortorder": "descending"}],"pagination": {"size": 10,"page": 1}}}'
44 mock_send_message.assert_called_with('POST', 'Get SDNC events',
45 (f"{BASE_URL}/rests/operations/data-provider:read-faultlog-list"), data=data, headers=HEADER, basic_auth=BASIC_AUTH)