From aea172385d378e1dadd02bf0365dfbb59c688375 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Wed, 25 Jul 2018 19:43:54 +0800 Subject: [PATCH] bugfix: check HTTP method before request --- httprunner/context.py | 1 + httprunner/runner.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/httprunner/context.py b/httprunner/context.py index 11d7736d..e4799c8c 100644 --- a/httprunner/context.py +++ b/httprunner/context.py @@ -17,6 +17,7 @@ class Context(object): self.testset_shared_variables_mapping = OrderedDict() self.testcase_variables_mapping = OrderedDict() self.testcase_parser = testcase.TestcaseParser() + self.evaluated_validators = [] self.init_context() def init_context(self, level='testset'): diff --git a/httprunner/runner.py b/httprunner/runner.py index ca7b49db..538143f9 100644 --- a/httprunner/runner.py +++ b/httprunner/runner.py @@ -156,6 +156,14 @@ class Runner(object): except KeyError: raise exceptions.ParamsError("URL or METHOD missed!") + # TODO: move method validation to json schema + valid_methods = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"] + if method.upper() not in valid_methods: + err_msg = u"ParamsError: invalid HTTP method! => {}\n".format(method) + err_msg += "available HTTP methods: {}".format("/".join(valid_methods)) + logger.log_error(err_msg) + raise exceptions.ParamsError(err_msg) + logger.log_info("{method} {url}".format(method=method, url=url)) logger.log_debug("request kwargs(raw): {kwargs}".format(kwargs=parsed_request))