mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
TestcaseParser: add update_variables_binds
This commit is contained in:
@@ -6,7 +6,13 @@ 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, variables_binds={}):
|
def update_variables_binds(self, variables_mapping):
|
||||||
|
""" update variables binds with new mapping.
|
||||||
|
"""
|
||||||
|
if variables_mapping:
|
||||||
|
self.variables_binds.update(variables_mapping)
|
||||||
|
|
||||||
|
def parse(self, testcase_template):
|
||||||
""" 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,12 +36,7 @@ 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):
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
new_variable_binds = {
|
new_variable_binds = {
|
||||||
"method": "GET"
|
"method": "GET"
|
||||||
}
|
}
|
||||||
parsed_testcase = self.testcase_parser.parse(testcase, new_variable_binds)
|
self.testcase_parser.update_variables_binds(new_variable_binds)
|
||||||
|
parsed_testcase = self.testcase_parser.parse(testcase)
|
||||||
|
|
||||||
self.assertIn("method", self.testcase_parser.variables_binds)
|
self.assertIn("method", self.testcase_parser.variables_binds)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|||||||
Reference in New Issue
Block a user