TestcaseParser: add update_variables_binds

This commit is contained in:
debugtalk
2017-06-26 14:43:06 +08:00
parent 668e17d45a
commit 298391324d
2 changed files with 9 additions and 7 deletions

View File

@@ -6,7 +6,13 @@ class TestcaseParser(object):
def __init__(self, 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.
variables marker: ${variable}.
@param testcase_template
@@ -30,12 +36,7 @@ class TestcaseParser(object):
"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)
def substitute(self, content):

View File

@@ -90,7 +90,8 @@ class TestcaseParserUnittest(unittest.TestCase):
new_variable_binds = {
"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.assertEqual(