1 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
19 from ONAPLibrary.Utilities import Utilities
22 class BaseSOKeywords(object):
23 """SO is an ONAP testing library for Robot Framework that provides functionality for interacting with the serivce
27 super(BaseSOKeywords, self).__init__()
28 self.application_id = "robot-ete"
29 self.uuid = Utilities()
30 self.builtin = BuiltIn()
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")
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)
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)
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)
57 def create_headers(self, accept="application/json"):
58 """Create the headers that are used by so"""
59 uuid = self.uuid.generate_uuid4()
62 "Content-Type": "application/json",
63 "X-TransactionId": self.application_id + "-" + uuid,
64 "X-FromAppId": self.application_id
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)
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)
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)