mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-01 05:49:40 +08:00
feat: make pytest files in chain style
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import unittest
|
||||
|
||||
from httprunner.make import main_make, convert_testcase_path, make_files_cache_set
|
||||
from httprunner.make import (
|
||||
main_make,
|
||||
convert_testcase_path,
|
||||
make_files_cache_set,
|
||||
make_config_chain_style,
|
||||
make_teststep_chain_style,
|
||||
)
|
||||
|
||||
|
||||
class TestLoader(unittest.TestCase):
|
||||
@@ -95,3 +101,42 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
|
||||
"examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py",
|
||||
testcase_python_list,
|
||||
)
|
||||
|
||||
def test_make_config_chain_style(self):
|
||||
config = {
|
||||
"name": "request methods testcase: validate with functions",
|
||||
"variables": {"foo1": "bar1", "foo2": 22},
|
||||
"base_url": "https://postman-echo.com",
|
||||
"verify": False,
|
||||
"path": "examples/postman_echo/request_methods/validate_with_functions_test.py",
|
||||
}
|
||||
self.assertEqual(
|
||||
make_config_chain_style(config),
|
||||
"""Config("request methods testcase: validate with functions").variables(**{'foo1': 'bar1', 'foo2': 22}).base_url("https://postman-echo.com").verify(False)""",
|
||||
)
|
||||
|
||||
def test_make_teststep_chain_style(self):
|
||||
step = {
|
||||
"name": "get with params",
|
||||
"variables": {"foo1": "bar1", "foo2": 123, "sum_v": "${sum_two(1, 2)}",},
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"url": "/get",
|
||||
"params": {"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"},
|
||||
"headers": {"User-Agent": "HttpRunner/${get_httprunner_version()}"},
|
||||
},
|
||||
"testcase": "CLS_LB(TestCaseDemo)CLS_RB",
|
||||
"extract": {
|
||||
"session_foo1": "body.args.foo1",
|
||||
"session_foo2": "body.args.foo2",
|
||||
},
|
||||
"validate": [
|
||||
{"eq": ["status_code", 200]},
|
||||
{"eq": ["body.args.sum_v", "3"]},
|
||||
],
|
||||
}
|
||||
teststep_chain_style = make_teststep_chain_style(step)
|
||||
self.assertEqual(
|
||||
teststep_chain_style,
|
||||
"""Step(RunRequest("get with params").with_variables(**{'foo1': 'bar1', 'foo2': 123, 'sum_v': '${sum_two(1, 2)}'}).get("/get").with_params(**{'foo1': '$foo1', 'foo2': '$foo2', 'sum_v': '$sum_v'}).with_headers(**{'User-Agent': 'HttpRunner/${get_httprunner_version()}'}).extract().with_jmespath("body.args.foo1", "session_foo1").with_jmespath("body.args.foo2", "session_foo2").validate().assert_equal("status_code", 200).assert_equal("body.args.sum_v", "3"))""",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user