Add new tests to validate O1
[it/dep.git] / smo-install / test / pythonsdk / src / oransdk / a1policymanagement / a1policymanagement.py
1 #!/usr/bin/env python3
2 ###
3 # ============LICENSE_START=======================================================
4 # ORAN SMO PACKAGE - PYTHONSDK TESTS
5 # ================================================================================
6 # Copyright (C) 2021-2022 AT&T Intellectual Property. All rights
7 #                             reserved.
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 # http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END============================================
21 # ===================================================================
22 #
23 ###
24
25 """ONAP A1 Policy Management."""
26
27 from typing import Dict
28 from onapsdk.onap_service import OnapService
29 from oransdk.configuration import settings
30
31 class A1policymanagement(OnapService):
32     """A1 Policy Management library."""
33
34     base_url = settings.A1_POLICY_MANAGEMENT_URL
35     header = {"Accept":"application/json", "Content-Type":"application/json"}
36
37     @classmethod
38     def check_status(cls) -> str:
39         """
40         Get the status of the A1 policy management component.
41
42         Returns:
43             the status of the A1 policy management component
44
45         """
46         url = f"{cls.base_url}/status"
47         status = cls.send_message('GET',
48                                   'Get A1 policy management status',
49                                   url)
50         return status
51
52     @classmethod
53     def get_policy_types(cls) -> Dict:
54         """
55         Get all the policy types.
56
57         Returns:
58             the list of policy types
59
60         """
61         url = f"{cls.base_url}/policy_types"
62         policy_types = cls.send_message_json('GET',
63                                              'Get all the policy types',
64                                              url)
65         return policy_types
66
67     @classmethod
68     def get_policy_type_agent(cls) -> Dict:
69         """
70         Get all the policy types from policy agent.
71
72         Returns:
73             the list of policy types
74
75         """
76         url = f"{cls.base_url}/a1-policy/v2/policy-types"
77         policy_types = cls.send_message_json('GET',
78                                              'Get all the policy types from policy agent',
79                                              url)
80         return policy_types
81
82     @classmethod
83     def get_policy(cls, policy_id) -> Dict:
84         """
85         Get policy.
86
87         Args:
88            type: the policy id
89
90         Returns:
91             the details of the policy
92
93         """
94         url = f"{cls.base_url}/a1-policy/v2/policies/{policy_id}"
95         policy = cls.send_message_json('GET',
96                                        'Get the policy with policy id',
97                                        url)
98         return policy
99
100
101     @classmethod
102     def create_service(cls,
103                        service_data) -> None:
104         """
105         Create service.
106
107         Args:
108            service_data: the service data in binary format
109
110         """
111         url = f"{cls.base_url}/a1-policy/v2/services"
112         cls.send_message('PUT',
113                          'Create Service',
114                          url,
115                          data=service_data,
116                          headers=cls.header)
117
118     @classmethod
119     def create_policy(cls,
120                       policy_data) -> None:
121         """
122         Create policy.
123
124         Args:
125            policy_data: the policy data in binary format
126
127         """
128         url = f"{cls.base_url}/a1-policy/v2/policies"
129         cls.send_message('PUT',
130                          'Create Policy',
131                          url,
132                          data=policy_data,
133                          headers=cls.header)