mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 00:17:37 +08:00
TestcaseParser: variable binds of testcase parser instance cat be updated.
This commit is contained in:
+6
-1
@@ -6,7 +6,7 @@ class TestcaseParser(object):
|
|||||||
def __init__(self, variables_binds={}):
|
def __init__(self, variables_binds={}):
|
||||||
self.variables_binds = variables_binds
|
self.variables_binds = variables_binds
|
||||||
|
|
||||||
def parse(self, testcase_template):
|
def parse(self, testcase_template, variables_binds={}):
|
||||||
""" parse testcase_template, replace all variables with bind value.
|
""" parse testcase_template, replace all variables with bind value.
|
||||||
variables marker: ${variable}.
|
variables marker: ${variable}.
|
||||||
@param testcase_template
|
@param testcase_template
|
||||||
@@ -30,7 +30,12 @@ class TestcaseParser(object):
|
|||||||
"msg": "user created successfully."
|
"msg": "user created successfully."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@param variables_binds
|
||||||
|
variable binds of testcase parser instance will be updated.
|
||||||
"""
|
"""
|
||||||
|
if variables_binds:
|
||||||
|
self.variables_binds.update(variables_binds)
|
||||||
|
|
||||||
return self.substitute(testcase_template)
|
return self.substitute(testcase_template)
|
||||||
|
|
||||||
def substitute(self, content):
|
def substitute(self, content):
|
||||||
|
|||||||
@@ -79,3 +79,21 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
with self.assertRaises(exception.ParamsError):
|
with self.assertRaises(exception.ParamsError):
|
||||||
self.testcase_parser.parse(testcase)
|
self.testcase_parser.parse(testcase)
|
||||||
|
|
||||||
|
def test_parse_testcase_with_new_variable_binds(self):
|
||||||
|
testcase = {
|
||||||
|
"request": {
|
||||||
|
"url": "http://127.0.0.1:5000/api/users/${uid}",
|
||||||
|
"method": "${method}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new_variable_binds = {
|
||||||
|
"method": "GET"
|
||||||
|
}
|
||||||
|
parsed_testcase = self.testcase_parser.parse(testcase, new_variable_binds)
|
||||||
|
|
||||||
|
self.assertIn("method", self.testcase_parser.variables_binds)
|
||||||
|
self.assertEqual(
|
||||||
|
parsed_testcase["request"]["method"],
|
||||||
|
new_variable_binds["method"]
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user