Merge pull request #14 from diaojunxian/master

bugfix: add maxreplace=1 to avoid similar variables are replaced by mistaken.
For instance, if user=1000, then "/$user/$userid" will be replaced to be "/1000/1000id".
This commit is contained in:
debugtalk
2017-08-03 13:34:29 +08:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

View File

@@ -49,7 +49,7 @@ def parse_variables(content, variable_mapping):
# content contains one or many variables
content = content.replace(
"${}".format(variable_name),
str(variable_value)
str(variable_value), 1
)
return content

View File

@@ -193,6 +193,19 @@ class TestcaseParserUnittest(unittest.TestCase):
"/users/100/training/1498?userId=100&data=1498"
)
def test_parse_variables_multiple_identical_variables(self):
variables_binds = {
"user": 100,
"userid": 1000,
"data": 1498
}
content = "/users/$user/$userid/$data?userId=$userid&data=$data"
self.assertEqual(
testcase.parse_content_with_bindings(content, variables_binds, {}),
"/users/100/1000/1498?userId=1000&data=1498"
)
def test_parse_content_with_bindings_functions(self):
import random, string
functions_binds = {