create music keywords and move over http keywords
[testsuite/python-testing-utils.git] / robotframework-onap / ONAPLibrary / MUSICKeywords.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 ONAPLibrary.Utilities import Utilities
20
21
22 class MUSICKeywords(object):
23     """MUSIC 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(MUSICKeywords, self).__init__()
28         self.application_id = "robot-ete"
29         self.uuid = Utilities()
30         self.builtin = BuiltIn()
31
32     @keyword
33     def run_get_request(self, endpoint, data_path, accept="application/json", auth=None):
34         """Runs an MUSIC get request"""
35         resp = self.get_request(endpoint, data_path, accept, auth)
36         return resp
37
38     def get_request(self, endpoint, data_path, accept="application/json", auth=None):
39         """Runs an MUSIC get request"""
40         logger.info("Creating session" + endpoint)
41         RequestsLibrary().create_session("music", endpoint, auth=auth)
42         resp = RequestsLibrary().get_request("music", data_path, headers=self.create_headers(accept))
43         logger.info("Received response from music " + resp.text)
44         return resp
45
46     def create_headers(self, accept="application/json"):
47         """Create the headers that are used by MUSIC"""
48         uuid = self.uuid.generate_uuid4()
49         headers = {
50             "Accept": accept,
51             "Content-Type": "application/json",
52             "X-TransactionId": self.application_id + "-" + uuid,
53             "X-FromAppId": self.application_id
54         }
55         return headers
56
57     def run_health_check(self, endpoint, health_check_path):
58         """Runs MUSIC Health check"""
59         resp = self.run_get_request(endpoint, health_check_path)
60         self.builtin.should_be_equal_as_strings(resp.status_code, "200")
61         self.builtin.should_be_equal_as_strings(resp.json()['status'], "SUCCESS")
62
63     def run_cassandra_connection_check(self, endpoint, health_check_path):
64         """Confirm MUSIC's connection to Cassandra in active"""
65         resp = self.run_get_request(endpoint, health_check_path)
66         self.builtin.should_be_equal_as_strings(resp.status_code, "200")
67         self.builtin.should_be_equal_as_strings(resp.json()['Cassandra'], "Active")
68