diff --git a/ate/testcase.py b/ate/testcase.py index 80b1c6aa..194e338a 100644 --- a/ate/testcase.py +++ b/ate/testcase.py @@ -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): diff --git a/test/test_testcase.py b/test/test_testcase.py index 5ae5aa55..b6cfcb75 100644 --- a/test/test_testcase.py +++ b/test/test_testcase.py @@ -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"] + )