From 372cac78ab3c727b691f22ee1c476452fab61e0a Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 25 Apr 2022 13:32:02 +0800 Subject: [PATCH] fix: demo function compatibility --- .../testcases/demo_requests.yml | 2 +- .../demo-with-py-plugin/testcases/__init__.py | 1 + .../testcases/demo_ref_testcase_test.py | 60 ++++++++++++++ .../testcases/demo_requests.yml | 2 +- .../testcases/demo_requests_test.py | 83 +++++++++++++++++++ .../templates/testcases/demo_requests.yml | 2 +- .../templates/testcases/demo_requests_test.py | 2 +- 7 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 examples/demo-with-py-plugin/testcases/__init__.py create mode 100644 examples/demo-with-py-plugin/testcases/demo_ref_testcase_test.py create mode 100644 examples/demo-with-py-plugin/testcases/demo_requests_test.py diff --git a/examples/demo-with-go-plugin/testcases/demo_requests.yml b/examples/demo-with-go-plugin/testcases/demo_requests.yml index 7c8be928..cae1b491 100644 --- a/examples/demo-with-go-plugin/testcases/demo_requests.yml +++ b/examples/demo-with-go-plugin/testcases/demo_requests.yml @@ -15,7 +15,7 @@ teststeps: variables: foo1: bar11 foo2: bar21 - sum_v: "${sum_two(1, 2)}" + sum_v: "${sum_two_int(1, 2)}" request: method: GET url: /get diff --git a/examples/demo-with-py-plugin/testcases/__init__.py b/examples/demo-with-py-plugin/testcases/__init__.py new file mode 100644 index 00000000..70cfba53 --- /dev/null +++ b/examples/demo-with-py-plugin/testcases/__init__.py @@ -0,0 +1 @@ +# NOTICE: Generated By HttpRunner. DO NOT EDIT! diff --git a/examples/demo-with-py-plugin/testcases/demo_ref_testcase_test.py b/examples/demo-with-py-plugin/testcases/demo_ref_testcase_test.py new file mode 100644 index 00000000..e88b8d08 --- /dev/null +++ b/examples/demo-with-py-plugin/testcases/demo_ref_testcase_test.py @@ -0,0 +1,60 @@ +# NOTE: Generated By HttpRunner v3.1.11 +# FROM: testcases/demo_ref_testcase.yml + + +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent.parent)) + + +from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase + +from testcases.demo_requests_test import TestCaseDemoRequests as DemoRequests + + +class TestCaseDemoRefTestcase(HttpRunner): + + config = ( + Config("request methods testcase: reference testcase") + .variables( + **{ + "foo1": "testsuite_config_bar1", + "expect_foo1": "testsuite_config_bar1", + "expect_foo2": "config_bar2", + } + ) + .base_url("https://postman-echo.com") + .verify(False) + ) + + teststeps = [ + Step( + RunTestCase("request with functions") + .with_variables( + **{"foo1": "testcase_ref_bar1", "expect_foo1": "testcase_ref_bar1"} + ) + .call(DemoRequests) + .export(*["foo3"]) + ), + Step( + RunRequest("post form data") + .with_variables(**{"foo1": "bar1"}) + .post("/post") + .with_headers( + **{ + "User-Agent": "HttpRunner/${get_httprunner_version()}", + "Content-Type": "application/x-www-form-urlencoded", + } + ) + .with_data("foo1=$foo1&foo2=$foo3") + .validate() + .assert_equal("status_code", 200) + .assert_equal("body.form.foo1", "bar1") + .assert_equal("body.form.foo2", "bar21") + ), + ] + + +if __name__ == "__main__": + TestCaseDemoRefTestcase().test_start() diff --git a/examples/demo-with-py-plugin/testcases/demo_requests.yml b/examples/demo-with-py-plugin/testcases/demo_requests.yml index 7c8be928..cae1b491 100644 --- a/examples/demo-with-py-plugin/testcases/demo_requests.yml +++ b/examples/demo-with-py-plugin/testcases/demo_requests.yml @@ -15,7 +15,7 @@ teststeps: variables: foo1: bar11 foo2: bar21 - sum_v: "${sum_two(1, 2)}" + sum_v: "${sum_two_int(1, 2)}" request: method: GET url: /get diff --git a/examples/demo-with-py-plugin/testcases/demo_requests_test.py b/examples/demo-with-py-plugin/testcases/demo_requests_test.py new file mode 100644 index 00000000..b5c34bc2 --- /dev/null +++ b/examples/demo-with-py-plugin/testcases/demo_requests_test.py @@ -0,0 +1,83 @@ +# NOTE: Generated By HttpRunner v3.1.11 +# FROM: testcases/demo_requests.yml + + +from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase + + +class TestCaseDemoRequests(HttpRunner): + + config = ( + Config("request methods testcase with functions") + .variables( + **{ + "foo1": "config_bar1", + "foo2": "config_bar2", + "expect_foo1": "config_bar1", + "expect_foo2": "config_bar2", + } + ) + .base_url("https://postman-echo.com") + .verify(False) + .export(*["foo3"]) + ) + + teststeps = [ + Step( + RunRequest("get with params") + .with_variables( + **{"foo1": "bar11", "foo2": "bar21", "sum_v": "${sum_two_int(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.foo2", "foo3") + .validate() + .assert_equal("status_code", 200) + .assert_equal("body.args.foo1", "bar11") + .assert_equal("body.args.sum_v", "3") + .assert_equal("body.args.foo2", "bar21") + ), + Step( + RunRequest("post raw text") + .with_variables(**{"foo1": "bar12", "foo3": "bar32"}) + .post("/post") + .with_headers( + **{ + "User-Agent": "HttpRunner/${get_httprunner_version()}", + "Content-Type": "text/plain", + } + ) + .with_data( + "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3." + ) + .validate() + .assert_equal("status_code", 200) + .assert_equal( + "body.data", + "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32.", + ) + ), + Step( + RunRequest("post form data") + .with_variables(**{"foo2": "bar23"}) + .post("/post") + .with_headers( + **{ + "User-Agent": "HttpRunner/${get_httprunner_version()}", + "Content-Type": "application/x-www-form-urlencoded", + } + ) + .with_data("foo1=$foo1&foo2=$foo2&foo3=$foo3") + .validate() + .assert_equal("status_code", 200) + .assert_equal("body.form.foo1", "$expect_foo1") + .assert_equal("body.form.foo2", "bar23") + .assert_equal("body.form.foo3", "bar21") + ), + ] + + +if __name__ == "__main__": + TestCaseDemoRequests().test_start() diff --git a/hrp/internal/scaffold/templates/testcases/demo_requests.yml b/hrp/internal/scaffold/templates/testcases/demo_requests.yml index 7c8be928..cae1b491 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_requests.yml +++ b/hrp/internal/scaffold/templates/testcases/demo_requests.yml @@ -15,7 +15,7 @@ teststeps: variables: foo1: bar11 foo2: bar21 - sum_v: "${sum_two(1, 2)}" + sum_v: "${sum_two_int(1, 2)}" request: method: GET url: /get diff --git a/hrp/internal/scaffold/templates/testcases/demo_requests_test.py b/hrp/internal/scaffold/templates/testcases/demo_requests_test.py index 5ce8a6d8..e54a7faa 100644 --- a/hrp/internal/scaffold/templates/testcases/demo_requests_test.py +++ b/hrp/internal/scaffold/templates/testcases/demo_requests_test.py @@ -26,7 +26,7 @@ class TestCaseDemoRequests(HttpRunner): Step( RunRequest("get with params") .with_variables( - **{"foo1": "bar11", "foo2": "bar21", "sum_v": "${sum_two(1, 2)}"} + **{"foo1": "bar11", "foo2": "bar21", "sum_v": "${sum_two_int(1, 2)}"} ) .get("/get") .with_params(**{"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"})