From 51687d0ee9a016d4bcd5f7385f8b4230ee5ab8a1 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Sun, 15 Mar 2015 23:52:18 -0400 Subject: [PATCH] Fix pep8 violations in restlib Change-Id: I6a11e10183837517cc326864832e46065cb705ac Signed-off-by: Thanh Ha --- test/tools/Robot_Tool/libraries/restlib.py | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/test/tools/Robot_Tool/libraries/restlib.py b/test/tools/Robot_Tool/libraries/restlib.py index f1f8858de7..11a8dd35f2 100644 --- a/test/tools/Robot_Tool/libraries/restlib.py +++ b/test/tools/Robot_Tool/libraries/restlib.py @@ -10,7 +10,7 @@ import requests # Global variables DEFAULT_CONTROLLER_IP = '127.0.0.1' -#DEFAULT_CONTROLLER_IP = '9.186.105.113' #just for temp test +# DEFAULT_CONTROLLER_IP = '9.186.105.113' #just for temp test DEFAULT_PORT = '8080' DEFAULT_PREFIX = 'http://' + DEFAULT_CONTROLLER_IP + ':' + DEFAULT_PORT DEFAULT_CONTAINER = 'default' @@ -29,7 +29,7 @@ def do_post_request(url, content_type, payload=None, user=DEFAULT_USER, password headers = {} if content_type == 'json': headers = {'Content-type': 'application/json', 'Accept': 'application/json'} - if payload != None: + if payload is not None: data = json.dumps(payload) elif content_type == 'xml': headers = {'Content-type': 'application/xml', 'Accept': 'application/xml'} @@ -38,7 +38,7 @@ def do_post_request(url, content_type, payload=None, user=DEFAULT_USER, password try: r = requests.post(url, data, headers=headers, auth=(user, password), timeout=TIMEOUTS) r.raise_for_status() - except (requests.exceptions.HTTPError, requests.exceptions.Timeout) as e: + except (requests.exceptions.HTTPError, requests.exceptions.Timeout): return 400 else: return r.status_code @@ -69,7 +69,7 @@ def do_put_request(url, content_type, payload=None, user=DEFAULT_USER, password= headers = {} if content_type == 'json': headers = {'Content-type': 'application/json', 'Accept': 'application/json'} - if payload != None: + if payload is not None: data = json.dumps(payload) elif content_type == 'xml': headers = {'Content-type': 'application/xml', 'Accept': 'application/xml'} @@ -78,7 +78,7 @@ def do_put_request(url, content_type, payload=None, user=DEFAULT_USER, password= try: r = requests.put(url, data, headers=headers, auth=(user, password), timeout=TIMEOUTS) r.raise_for_status() - except (requests.exceptions.HTTPError, requests.exceptions.Timeout) as e: + except (requests.exceptions.HTTPError, requests.exceptions.Timeout): return 400 else: return r.status_code @@ -105,16 +105,16 @@ def convert_result_to_list(result): Convert the result content to list. ''' list2 = [] - #print result + # print result content = result.values() for list1 in content: list2 = [dict1.values() for dict1 in list1] - #print list2 + # print list2 list3 = [] for list4 in list2: for element in list4: list3.append(element) - #print list3 + # print list3 return list3 @@ -131,21 +131,20 @@ def do_get_request_with_response_content(url, content_type, user=DEFAULT_USER, p print e return None else: - if r != None: + if r is not None: if content_type == 'json': content = r.json() return convert_result_to_list(content) if convert_to_list else content - elif content_type == 'xml':#TODO: add parser to xml + elif content_type == 'xml': # TODO: add parser to xml return None if __name__ == '__main__': - #example - #Note: in json body, all field name and value (if it is string type) must be enclosed in double quotes. - #This constraint maybe cause by json parser. + # example + # Note: in json body, all field name and value (if it is string type) must be enclosed in double quotes. + # This constraint maybe cause by json parser. body = {"status": "Success", "dstNodeConnector": "OF|1@OF|00:00:00:00:00:00:00:01", "name": "link3", "srcNodeConnector": "OF|1@OF|00:00:00:00:00:00:00:03"} url = 'http://127.0.0.1:8080/controller/nb/v2/topology/default/userLink/link3' content_type = 'json' print do_put_request(url, content_type, body) - -- 2.36.6