mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-21 08:10:24 +08:00
make variables marker unified to be
This commit is contained in:
22
ate/utils.py
22
ate/utils.py
@@ -2,8 +2,8 @@ import hashlib
|
||||
import json
|
||||
import os.path
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
|
||||
import yaml
|
||||
|
||||
from ate.exception import ParamsError
|
||||
@@ -190,3 +190,23 @@ def load_testcases_by_path(path):
|
||||
|
||||
else:
|
||||
return []
|
||||
|
||||
def parse_content_with_variables(content, variables_binds):
|
||||
""" replace variables with bind value
|
||||
"""
|
||||
# check if content includes ${variable}
|
||||
matched = re.match(r"(.*)\$\{(.*)\}(.*)", content)
|
||||
if matched:
|
||||
# this is a variable, and will replace with its bind value
|
||||
variable_name = matched.group(2)
|
||||
value = variables_binds.get(variable_name)
|
||||
if value is None:
|
||||
raise ParamsError(
|
||||
"%s is not defined in bind variables!" % variable_name)
|
||||
if matched.group(1) or matched.group(3):
|
||||
# e.g. /api/users/${uid}
|
||||
return re.sub(r"\$\{.*\}", value, content)
|
||||
|
||||
return value
|
||||
|
||||
return content
|
||||
|
||||
Reference in New Issue
Block a user