2 # SPDX-License-Identifier: Apache-2.0
3 """Test Policy module."""
5 from unittest import mock
6 from oransdk.policy.policy import OranPolicy, PolicyType
8 HEADER = {"Accept": "application/json", "Content-Type": "application/json"}
9 API_URL = "https://localhost:6969"
10 PAP_URL = "https://localhost:6969"
11 BASIC_AUTH = {'username': 'dcae@dcae.onap.org', 'password': 'demo123456!'}
13 def test_initialization():
14 """Class initialization test."""
16 assert isinstance(policy, OranPolicy)
19 @mock.patch.object(OranPolicy, 'send_message_json')
20 def test_get_components_status(mock_send_message_json):
21 """Test Policy's class method."""
22 OranPolicy.get_components_status(BASIC_AUTH)
23 mock_send_message_json.assert_called_once_with('GET',
24 'Get status of Policy component',
25 (f"{PAP_URL}/policy/pap/v1/components/healthcheck"),
26 basic_auth=BASIC_AUTH)
28 @mock.patch.object(OranPolicy, 'send_message_json')
29 def test_get_policy_status(mock_send_message_json):
30 """Test Policy's class method."""
31 OranPolicy.get_policy_status(BASIC_AUTH)
32 mock_send_message_json.assert_called_once_with('GET',
33 'Get status of all the policies',
34 (f"{PAP_URL}/policy/pap/v1/policies/status"),
35 basic_auth=BASIC_AUTH)
38 @mock.patch.object(OranPolicy, 'send_message_json')
39 def test_get_policy(mock_send_message_json):
40 """Test Policy's class method."""
41 OranPolicy.get_policy(PolicyType(type="test_type", version="type_version"),
42 "policy_name", "policy_version", BASIC_AUTH)
43 mock_send_message_json.assert_called_once_with('GET',
45 (f"{API_URL}/policy/api/v1/policytypes/test_type/versions/"\
46 + "type_version/policies/policy_name/versions/policy_version"),
47 basic_auth=BASIC_AUTH)
50 @mock.patch.object(OranPolicy, 'send_message')
51 def test_create_policy(mock_send_message):
52 """Test Policy's class method."""
53 OranPolicy.create_policy(PolicyType(type="test_type", version="type_version"), {}, BASIC_AUTH)
54 mock_send_message.assert_called_once_with('POST',
56 (f"{API_URL}/policy/api/v1/policytypes/test_type/"\
57 + "versions/type_version/policies"),
60 basic_auth=BASIC_AUTH)
62 @mock.patch.object(OranPolicy, 'send_message')
63 def test_deploy_policy(mock_send_message):
64 """Test Policy's class method."""
65 OranPolicy.deploy_policy({}, BASIC_AUTH)
66 mock_send_message.assert_called_once_with('POST',
68 (f"{API_URL}/policy/pap/v1/pdps/policies"),
71 basic_auth=BASIC_AUTH)