X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=smo-install%2Ftest%2Fpythonsdk%2Funit-tests%2Ftest_policy.py;fp=smo-install%2Ftest%2Fpythonsdk%2Funit-tests%2Ftest_policy.py;h=acbcda386751404cc7060444773e64cf31df3ea8;hb=285d9a5c96b23594b419d95c71c5d6a2cf52052e;hp=0000000000000000000000000000000000000000;hpb=0fd7875b5673d8d9b56c73adff2c8368d95e825b;p=it%2Fdep.git diff --git a/smo-install/test/pythonsdk/unit-tests/test_policy.py b/smo-install/test/pythonsdk/unit-tests/test_policy.py new file mode 100644 index 00000000..acbcda38 --- /dev/null +++ b/smo-install/test/pythonsdk/unit-tests/test_policy.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Test Policy module.""" + +from unittest import mock +from oransdk.policy.policy import OranPolicy, PolicyType + +HEADER = {"Accept": "application/json", "Content-Type": "application/json"} +API_URL = "https://localhost:6969" +PAP_URL = "https://localhost:6969" +BASIC_AUTH = {'username': 'dcae@dcae.onap.org', 'password': 'demo123456!'} + +def test_initialization(): + """Class initialization test.""" + policy = OranPolicy() + assert isinstance(policy, OranPolicy) + + +@mock.patch.object(OranPolicy, 'send_message_json') +def test_get_components_status(mock_send_message_json): + """Test Policy's class method.""" + OranPolicy.get_components_status(BASIC_AUTH) + mock_send_message_json.assert_called_once_with('GET', + 'Get status of Policy component', + (f"{PAP_URL}/policy/pap/v1/components/healthcheck"), + basic_auth=BASIC_AUTH) + +@mock.patch.object(OranPolicy, 'send_message_json') +def test_get_policy_status(mock_send_message_json): + """Test Policy's class method.""" + OranPolicy.get_policy_status(BASIC_AUTH) + mock_send_message_json.assert_called_once_with('GET', + 'Get status of all the policies', + (f"{PAP_URL}/policy/pap/v1/policies/status"), + basic_auth=BASIC_AUTH) + + +@mock.patch.object(OranPolicy, 'send_message_json') +def test_get_policy(mock_send_message_json): + """Test Policy's class method.""" + OranPolicy.get_policy(PolicyType(type="test_type", version="type_version"), + "policy_name", "policy_version", BASIC_AUTH) + mock_send_message_json.assert_called_once_with('GET', + 'Get the policy', + (f"{API_URL}/policy/api/v1/policytypes/test_type/versions/"\ + + "type_version/policies/policy_name/versions/policy_version"), + basic_auth=BASIC_AUTH) + + +@mock.patch.object(OranPolicy, 'send_message') +def test_create_policy(mock_send_message): + """Test Policy's class method.""" + OranPolicy.create_policy(PolicyType(type="test_type", version="type_version"), {}, BASIC_AUTH) + mock_send_message.assert_called_once_with('POST', + 'Create Policy', + (f"{API_URL}/policy/api/v1/policytypes/test_type/"\ + + "versions/type_version/policies"), + data={}, + headers=HEADER, + basic_auth=BASIC_AUTH) + +@mock.patch.object(OranPolicy, 'send_message') +def test_deploy_policy(mock_send_message): + """Test Policy's class method.""" + OranPolicy.deploy_policy({}, BASIC_AUTH) + mock_send_message.assert_called_once_with('POST', + 'Deploy Policy', + (f"{API_URL}/policy/pap/v1/pdps/policies"), + data={}, + headers=HEADER, + basic_auth=BASIC_AUTH)