Add ORAN Python SDK first draft
[it/dep.git] / smo-install / test / pythonsdk / unit-tests / test_policy.py
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 (file)
index 0000000..acbcda3
--- /dev/null
@@ -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)