diff options
Diffstat (limited to 'cmso-robot/robot/locallibrary/cmsoUtils')
7 files changed, 108 insertions, 0 deletions
diff --git a/cmso-robot/robot/locallibrary/cmsoUtils/CurlLibrary.py b/cmso-robot/robot/locallibrary/cmsoUtils/CurlLibrary.py new file mode 100644 index 0000000..44c6229 --- /dev/null +++ b/cmso-robot/robot/locallibrary/cmsoUtils/CurlLibrary.py @@ -0,0 +1,13 @@ +from curl import Curl + +class CurlLibrary: + + + def get_zip(self, url, filename): + fp = open(filename, "wb") + c = Curl() + c.get(url, ) + c.set_option(c.WRITEDATA, fp) + c.perform() + c.close() + fp.close()
\ No newline at end of file diff --git a/cmso-robot/robot/locallibrary/cmsoUtils/HTTPUtils.py b/cmso-robot/robot/locallibrary/cmsoUtils/HTTPUtils.py new file mode 100644 index 0000000..f9d380c --- /dev/null +++ b/cmso-robot/robot/locallibrary/cmsoUtils/HTTPUtils.py @@ -0,0 +1,21 @@ +import urllib +from selenium import webdriver +import base64 + +class HTTPUtils: + """HTTPUtils is common resource for simple http helper keywords.""" + + def url_encode_string(self, barestring): + """URL Encode String takes in a string and converts into 'percent-encoded' string""" + return urllib.quote_plus(barestring) + + def ff_profile(self): + fp =webdriver.FirefoxProfile() + fp.set_preference("dom.max_script_run_time",120) + fp.update_preferences() + return fp.path + + def b64_encode(self, instring): + "" + return base64.b64encode(instring) + diff --git a/cmso-robot/robot/locallibrary/cmsoUtils/JSONUtils.py b/cmso-robot/robot/locallibrary/cmsoUtils/JSONUtils.py new file mode 100644 index 0000000..5df1e5c --- /dev/null +++ b/cmso-robot/robot/locallibrary/cmsoUtils/JSONUtils.py @@ -0,0 +1,37 @@ +import json + +from deepdiff import DeepDiff + +class JSONUtils: + """JSONUtils is common resource for simple json helper keywords.""" + + def json_equals(self, left, right): + """JSON Equals takes in two strings or json objects, converts them into json if needed and then compares them, returning if they are equal or not.""" + if isinstance(left, basestring): + left_json = json.loads(left); + else: + left_json = left; + if isinstance(right, basestring): + right_json = json.loads(right); + else: + right_json = right; + + ddiff = DeepDiff(left_json, right_json, ignore_order=True); + if ddiff == {}: + return True; + else: + return False; + + def json_escape(self, jsonObject): + jsonstr = json.dumps(jsonObject) + outstr = jsonstr.replace('"', '\\"').replace('\n', '\\n') + return outstr + + def make_list_into_dict(self, listOfDicts, key): + """ Converts a list of dicts that contains a field that has a unique key into a dict of dicts """ + d = {} + if isinstance(listOfDicts, list): + for thisDict in listOfDicts: + v = thisDict[key] + d[v] = thisDict + return d
\ No newline at end of file diff --git a/cmso-robot/robot/locallibrary/cmsoUtils/OSUtils.py b/cmso-robot/robot/locallibrary/cmsoUtils/OSUtils.py new file mode 100644 index 0000000..78968f0 --- /dev/null +++ b/cmso-robot/robot/locallibrary/cmsoUtils/OSUtils.py @@ -0,0 +1,14 @@ +from sys import platform + +class OSUtils: + """ Utilities useful for constructing OpenStack HEAT requests """ + + def get_normalized_os(self): + os = platform + if platform == "linux" or platform == "linux2": + os = 'linux64' + elif platform == "darwin": + os = 'mac64' + elif platform == "win32": + os = platform + return os diff --git a/cmso-robot/robot/locallibrary/cmsoUtils/RequestsClientCert.py b/cmso-robot/robot/locallibrary/cmsoUtils/RequestsClientCert.py new file mode 100644 index 0000000..e1fd66f --- /dev/null +++ b/cmso-robot/robot/locallibrary/cmsoUtils/RequestsClientCert.py @@ -0,0 +1,7 @@ + +class RequestsClientCert: + """RequestsClientCert allows adding a client cert to the Requests Robot Library.""" + + def add_client_cert(self, session, cert): + """Add Client Cert takes in a requests session object and a string path to the cert""" + session.cert = cert
\ No newline at end of file diff --git a/cmso-robot/robot/locallibrary/cmsoUtils/StringTemplater.py b/cmso-robot/robot/locallibrary/cmsoUtils/StringTemplater.py new file mode 100644 index 0000000..680600f --- /dev/null +++ b/cmso-robot/robot/locallibrary/cmsoUtils/StringTemplater.py @@ -0,0 +1,8 @@ +from string import Template + +class StringTemplater: + """StringTemplater is common resource for templating with strings.""" + + def template_string(self, template, values): + """Template String takes in a string and its values and converts it using the string.Template class""" + return Template(template).substitute(values)
\ No newline at end of file diff --git a/cmso-robot/robot/locallibrary/cmsoUtils/UUID.py b/cmso-robot/robot/locallibrary/cmsoUtils/UUID.py new file mode 100644 index 0000000..15567ce --- /dev/null +++ b/cmso-robot/robot/locallibrary/cmsoUtils/UUID.py @@ -0,0 +1,8 @@ +import uuid + +class UUID: + """UUID is a simple library that generates a uuid""" + + def generate_UUID(self): + """generate a uuid""" + return uuid.uuid4()
\ No newline at end of file |