deelete requests client cert and copy dns
[testsuite/python-testing-utils.git] / robotframework-onap / ONAPLibrary / BaseSOKeywords.py
1 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 from RequestsLibrary import RequestsLibrary
15 from robot.api import logger
16 from robot.api.deco import keyword
17 from robot.libraries.BuiltIn import BuiltIn
18
19 from eteutils.UUID import UUID
20
21
22 class BaseSOKeywords(object):
23     """SO is an ONAP testing library for Robot Framework that provides functionality for interacting with the serivce
24     orchestrator. """
25
26     def __init__(self):
27         super(BaseSOKeywords, self).__init__()
28         self.application_id = "robot-ete"
29         self.uuid = UUID()
30         self.builtin = BuiltIn()
31
32     @keyword
33     def run_get_request(self, endpoint, data_path, accept="application/json", auth=None):
34         """Runs an SO get request"""
35         resp = self.get_request(endpoint, data_path, accept, auth)
36         self.builtin.should_be_equal_as_strings(resp.status_code, "200")
37         return resp
38
39     @keyword
40     def run_post_request(self, endpoint, data_path, data, accept="application/json", auth=None):
41         """Runs an SO post request"""
42         return self.post_request(endpoint, data_path, data, accept, auth)
43
44     @keyword
45     def run_put_request(self, endpoint, data_path, data, accept="application/json", auth=None):
46         """Runs an SO post request"""
47         return self.put_request(endpoint, data_path, data, accept, auth)
48
49     def get_request(self, endpoint, data_path, accept="application/json", auth=None):
50         """Runs an SO get request"""
51         logger.info("Creating session" + endpoint)
52         RequestsLibrary().create_session("so", endpoint, auth=auth)
53         resp = RequestsLibrary().get_request("so", data_path, headers=self.create_headers(accept))
54         logger.info("Received response from so " + resp.text)
55         return resp
56
57     def create_headers(self, accept="application/json"):
58         """Create the headers that are used by so"""
59         uuid = self.uuid.generate_UUID()
60         headers = {
61             "Accept": accept,
62             "Content-Type": "application/json",
63             "X-TransactionId": self.application_id + "-" + uuid,
64             "X-FromAppId": self.application_id
65         }
66         return headers
67
68     def post_request(self, endpoint, data_path, data, accept="application/json", auth=None):
69         """Runs an SO post request"""
70         logger.info("Creating session" + endpoint)
71         RequestsLibrary().create_session("so", endpoint, auth=auth)
72         resp = RequestsLibrary().post_request("so", data_path, data=data, headers=self.create_headers(accept))
73         logger.info("Received response from so " + resp.text)
74         return resp
75
76     def put_request(self, endpoint, data_path, data, accept="application/json", auth=None):
77         """Runs an SO post request"""
78         logger.info("Creating session" + endpoint)
79         RequestsLibrary().create_session("so", endpoint, auth=auth)
80         resp = RequestsLibrary().put_request("so", data_path, data=data, headers=self.create_headers(accept))
81         logger.info("Received response from so " + resp.text)
82         return resp
83
84     def delete_request(self, endpoint, data_path, data, accept="application/json", auth=None):
85         """Runs an SO post request"""
86         logger.info("Creating session" + endpoint)
87         RequestsLibrary().create_session("so", endpoint, auth=auth)
88         resp = RequestsLibrary().delete_request("so", data_path, data=data, headers=self.create_headers(accept))
89         logger.info("Received response from so " + resp.text)
90         return resp