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", "o-ru", BASIC_AUTH)
29 mock_send_message_json.assert_called_once_with('GET',
30 'Get status of Odu Oru connectivity',
31 (f"{BASE_URL}/rests/data/network-topology:network-topology/"\
32 + "topology=topology-netconf/node=o-du/yang-ext:mount/"\
33 + "o-ran-sc-du-hello-world:network-function/du-to-ru-connection=o-ru"),
34 basic_auth=BASIC_AUTH)
35 @mock.patch.object(OranSdnc, 'send_message')
36 def test_get_devices(mock_send_message):
37 """Test Sdnc's class method."""
38 OranSdnc.get_devices("device", BASIC_AUTH)
39 mock_send_message.assert_called_with('GET', 'Get status of Device connectivity',
40 (f"{BASE_URL}/rests/data/network-topology:network-topology/topology=topology-netconf/node=device"), basic_auth=BASIC_AUTH)
41 @mock.patch.object(OranSdnc, 'send_message')
42 def test_get_events(mock_send_message):
43 """Test Sdnc's class method."""
44 OranSdnc.get_events(BASIC_AUTH, "device")
45 data = '{"input": {"filter": [ {"property": "node-id", "filtervalue": " device "}],"sortorder":[{"property": "timestamp","sortorder": "descending"}],"pagination": {"size": 10,"page": 1}}}'
46 mock_send_message.assert_called_with('POST', 'Get SDNC events',
47 (f"{BASE_URL}/rests/operations/data-provider:read-faultlog-list"), data=data, headers=HEADER, basic_auth=BASIC_AUTH)