From 2533bd8033e3ed1005542ae63abd4f5987c474fe Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Thu, 26 May 2016 14:30:24 +0800 Subject: eliminate flake8 violation in testAPI except dashboard dir JIRA: FUNCTEST-262 Change-Id: Ib77bb080111392b8e3248c5e6152f55c12b8c67c Signed-off-by: SerenaFeng --- .../tornado_swagger_ui/example/basic.py | 34 ++++++++++++---------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'utils/test/result_collection_api/tornado_swagger_ui/example') diff --git a/utils/test/result_collection_api/tornado_swagger_ui/example/basic.py b/utils/test/result_collection_api/tornado_swagger_ui/example/basic.py index 1731bfd17..93ff00b43 100644 --- a/utils/test/result_collection_api/tornado_swagger_ui/example/basic.py +++ b/utils/test/result_collection_api/tornado_swagger_ui/example/basic.py @@ -22,15 +22,21 @@ class PropertySubclass: class Item: """ @description: - This is an example of a model class that has parameters in its constructor - and the fields in the swagger spec are derived from the parameters to __init__. + This is an example of a model class that has parameters in its + constructor and the fields in the swagger spec are derived from + the parameters to __init__. @notes: - In this case we would have property1, name as required parameters and property3 as optional parameter. + In this case we would have property1, name as required parameters + and property3 as optional parameter. @property property3: Item description @ptype property3: L{PropertySubclass} @ptype property4: C{list} of L{PropertySubclass} """ - def __init__(self, property1, property2=None, property3=None, property4=None): + def __init__(self, + property1, + property2=None, + property3=None, + property4=None): self.property1 = property1 self.property2 = property2 self.property3 = property3 @@ -78,17 +84,17 @@ class GenericApiHandler(RequestHandler): pass def prepare(self): - if not (self.request.method == "GET" or self.request.method == "DELETE"): - if self.request.headers.get("Content-Type") is not None: - if self.request.headers["Content-Type"].startswith(DEFAULT_REPRESENTATION): + if self.request.method != "GET" and self.request.method != "DELETE": + self.json_args = None + content_type = self.request.headers.get("Content-Type") + if content_type is not None: + if content_type.startswith(DEFAULT_REPRESENTATION): try: self.json_args = json.loads(self.request.body) except (ValueError, KeyError, TypeError) as error: raise HTTPError(HTTP_BAD_REQUEST, "Bad Json format [{}]". format(error)) - else: - self.json_args = None def finish_request(self, json_object): self.write(json.dumps(json_object)) @@ -138,7 +144,8 @@ class ItemHandler(GenericApiHandler): @notes: get a item, - This will be added to the Implementation Notes.It lets you put very long text in your api. + This will be added to the Implementation Notes. + It lets you put very long text in your api. """ self.finish_request(items[arg].format_http()) @@ -148,8 +155,6 @@ class ItemHandler(GenericApiHandler): @description: delete a item @notes: delete a item in items - - This will be added to the Implementation Notes.It lets you put very long text in your api. """ del items[arg] self.finish_request("success") @@ -161,8 +166,7 @@ class ItemOptionParamHandler(GenericApiHandler): """ @return 200: case is created """ - print("ProjectHandler.post: %s -- %s -- %s" % (arg1, arg2, self.request.full_url())) - fs = open("/home/swagger/tornado-rest-swagger/%s/%s" % (arg1, arg2), "wb") + fs = open("/home/%s/%s" % (arg1, arg2), "wb") fs.write(self.request.body) self.write("success") @@ -193,7 +197,7 @@ class ItemQueryHandler(GenericApiHandler): res.append(value.format_http()) elif value.property2 == property2: res.append(value.format_http()) - elif items.has_key(property1): + elif property1 in items: if items.get(property1).property2 == property2: res.append(items.get(property1).format_http()) -- cgit 1.2.3-korg