TestcaseParser: variable binds of testcase parser instance cat be updated.

This commit is contained in:
httprunner
2017-06-26 10:55:17 +08:00
parent 7396bcd853
commit 2fe161f82d
2 changed files with 24 additions and 1 deletions

View File

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

@@ -79,3 +79,21 @@ class TestcaseParserUnittest(unittest.TestCase):
}
with self.assertRaises(exception.ParamsError):
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"]
)