mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
@@ -333,6 +333,8 @@ def print_io(in_out):
|
||||
for variable, value in in_out.items():
|
||||
if isinstance(value, tuple):
|
||||
continue
|
||||
elif isinstance(value, dict):
|
||||
value = json.dumps(value)
|
||||
|
||||
if is_py2:
|
||||
if isinstance(variable, unicode):
|
||||
|
||||
23
tests/data/demo_testcase.yml
Normal file
23
tests/data/demo_testcase.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
- config:
|
||||
name: "123$var_a"
|
||||
variables:
|
||||
- var_a: 0
|
||||
- var_c: "${sum_two(1, 2)}"
|
||||
parameters:
|
||||
- "var_a-var_b":
|
||||
- [11, 21]
|
||||
- [12, 22]
|
||||
- "app_version": "${gen_app_version()}"
|
||||
request: $demo_default_request
|
||||
|
||||
- test:
|
||||
name: testcase1-$var_a
|
||||
request:
|
||||
url: /api1
|
||||
method: GET
|
||||
headers:
|
||||
var_a: $var_a
|
||||
var_b: $var_b
|
||||
var_c: $var_c
|
||||
validate:
|
||||
- {"check": "status_code", "comparator": "eq", "expect": 200}
|
||||
@@ -8,6 +8,15 @@ from tests.api_server import HTTPBIN_SERVER, SECRET_KEY, gen_md5, get_sign
|
||||
|
||||
BASE_URL = "http://127.0.0.1:5000"
|
||||
|
||||
demo_default_request = {
|
||||
"base_url": "$BASE_URL",
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
}
|
||||
|
||||
def sum_two(m, n):
|
||||
return m + n
|
||||
|
||||
def sum_status_code(status_code, expect_sum):
|
||||
""" sum status code digits
|
||||
|
||||
@@ -359,6 +359,21 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
runner.project_mapping["debugtalk"]["functions"]
|
||||
)
|
||||
|
||||
def test_parse_tests(self):
|
||||
testcase_file_path = os.path.join(
|
||||
os.getcwd(), 'tests/data/demo_testcase.yml')
|
||||
runner = HttpRunner()
|
||||
testcases = runner.load_tests(testcase_file_path)
|
||||
parsed_testcases = runner.parse_tests(testcases)
|
||||
self.assertEqual(parsed_testcases[0]["config"]["variables"]["var_c"], 3)
|
||||
self.assertEqual(len(parsed_testcases), 2 * 2)
|
||||
self.assertEqual(
|
||||
parsed_testcases[0]["config"]["request"]["base_url"],
|
||||
'http://127.0.0.1:5000'
|
||||
)
|
||||
self.assertIsInstance(parsed_testcases, list)
|
||||
self.assertEqual(parsed_testcases[0]["config"]["name"], '12311')
|
||||
|
||||
|
||||
class TestLocustRunner(ApiServerUnittest):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user