mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 17:29:56 +08:00
fix base_url with variables
This commit is contained in:
@@ -815,10 +815,19 @@ def __parse_tests(tests, config, project_mapping):
|
||||
else:
|
||||
# case (2)
|
||||
if "base_url" in test_dict:
|
||||
base_url = test_dict.pop("base_url")
|
||||
base_url = parse_data(
|
||||
test_dict.pop("base_url"),
|
||||
test_dict["variables"],
|
||||
functions
|
||||
)
|
||||
request_url = parse_data(
|
||||
test_dict["request"]["url"],
|
||||
test_dict["variables"],
|
||||
functions
|
||||
)
|
||||
test_dict["request"]["url"] = utils.build_url(
|
||||
base_url,
|
||||
test_dict["request"]["url"]
|
||||
request_url
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -481,6 +481,94 @@ class TestParser(unittest.TestCase):
|
||||
self.assertEqual(test_dict1_variables["creator"], "user_test_001")
|
||||
self.assertEqual(test_dict1_variables["username"], "$creator")
|
||||
|
||||
def test_parse_tests_base_url_priority(self):
|
||||
""" base_url & verify: priority test_dict > config
|
||||
"""
|
||||
tests_mapping = {
|
||||
'testcases': [
|
||||
{
|
||||
'config': {
|
||||
'name': '',
|
||||
"base_url": "$host",
|
||||
'variables': {
|
||||
"host": "https://debugtalk"
|
||||
},
|
||||
"verify": False
|
||||
},
|
||||
'tests': [
|
||||
{
|
||||
'name': 'testcase1',
|
||||
"base_url": "https://httprunner.org",
|
||||
"variables": [
|
||||
{"creator": "user_test_002"},
|
||||
{"username": "$creator"}
|
||||
],
|
||||
'request': {'url': '/api1', 'method': 'GET', "verify": True}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
parser.parse_tests(tests_mapping)
|
||||
test_dict = tests_mapping["testcases"][0]["tests"][0]
|
||||
self.assertEqual(test_dict["request"]["url"], "https://httprunner.org/api1")
|
||||
self.assertEqual(test_dict["request"]["verify"], True)
|
||||
|
||||
def test_parse_tests_base_url_path_with_variable(self):
|
||||
tests_mapping = {
|
||||
'testcases': [
|
||||
{
|
||||
'config': {
|
||||
'name': '',
|
||||
"base_url": "$host1",
|
||||
'variables': {
|
||||
"host1": "https://debugtalk"
|
||||
}
|
||||
},
|
||||
'tests': [
|
||||
{
|
||||
'name': 'testcase1',
|
||||
"variables": {
|
||||
"host2": "https://httprunner.org"
|
||||
},
|
||||
'request': {'url': '$host2/api1', 'method': 'GET'}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
parser.parse_tests(tests_mapping)
|
||||
test_dict = tests_mapping["testcases"][0]["tests"][0]
|
||||
self.assertEqual(test_dict["request"]["url"], "https://httprunner.org/api1")
|
||||
|
||||
def test_parse_tests_base_url_test_dict(self):
|
||||
tests_mapping = {
|
||||
'testcases': [
|
||||
{
|
||||
'config': {
|
||||
'name': '',
|
||||
"base_url": "$host1",
|
||||
'variables': {
|
||||
"host1": "https://debugtalk"
|
||||
}
|
||||
},
|
||||
'tests': [
|
||||
{
|
||||
'name': 'testcase1',
|
||||
"base_url": "$host2",
|
||||
"variables": {
|
||||
"host2": "https://httprunner.org"
|
||||
},
|
||||
'request': {'url': '/api1', 'method': 'GET'}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
parser.parse_tests(tests_mapping)
|
||||
test_dict = tests_mapping["testcases"][0]["tests"][0]
|
||||
self.assertEqual(test_dict["request"]["url"], "https://httprunner.org/api1")
|
||||
|
||||
def test_parse_environ(self):
|
||||
os.environ["PROJECT_KEY"] = "ABCDEFGH"
|
||||
content = {
|
||||
|
||||
Reference in New Issue
Block a user