mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-07 08:22:41 +08:00
test: add unittest form testcase with abnormal path
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Release History
|
||||
|
||||
## 3.0.9 (2020-06-05)
|
||||
## 3.0.9 (2020-06-07)
|
||||
|
||||
**Fixed**
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/httpbin/basic.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/httpbin/hooks.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/httpbin/load_image.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/httpbin/upload.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/httpbin/validate.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml
|
||||
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman_echo/request_methods/hardcode.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman_echo/request_methods/request_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman_echo/request_methods/request_with_testcase_reference.yml
|
||||
|
||||
import os
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman_echo/request_methods/request_with_variables.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman_echo/request_methods/validate_with_functions.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# NOTICE: Generated By HttpRunner v3.0.9
|
||||
# NOTE: Generated By HttpRunner v3.0.9
|
||||
# FROM: examples/postman_echo/request_methods/validate_with_variables.yml
|
||||
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import argparse
|
||||
import enum
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -23,7 +24,7 @@ def init_parser_run(subparsers):
|
||||
return sub_parser_run
|
||||
|
||||
|
||||
def main_run(extra_args):
|
||||
def main_run(extra_args) -> enum.IntEnum:
|
||||
capture_message("start to run")
|
||||
# keep compatibility with v2
|
||||
extra_args = ensure_cli_args(extra_args)
|
||||
@@ -52,7 +53,7 @@ def main_run(extra_args):
|
||||
extra_args_new.append("--tb=short")
|
||||
|
||||
extra_args_new.extend(testcase_path_list)
|
||||
sys.exit(pytest.main(extra_args_new))
|
||||
return pytest.main(extra_args_new)
|
||||
|
||||
|
||||
def main():
|
||||
@@ -112,7 +113,7 @@ def main():
|
||||
sys.exit(0)
|
||||
|
||||
if sys.argv[1] == "run":
|
||||
main_run(extra_args)
|
||||
sys.exit(main_run(extra_args))
|
||||
elif sys.argv[1] == "startproject":
|
||||
main_scaffold(args)
|
||||
elif sys.argv[1] == "har2case":
|
||||
|
||||
@@ -29,7 +29,7 @@ pytest_files_made_cache_mapping: Dict[Text, Text] = {}
|
||||
pytest_files_run_set: Set = set()
|
||||
|
||||
__TEMPLATE__ = jinja2.Template(
|
||||
"""# NOTICE: Generated By HttpRunner v{{ version }}
|
||||
"""# NOTE: Generated By HttpRunner v{{ version }}
|
||||
# FROM: {{ testcase_path }}
|
||||
{% if imports_list %}
|
||||
import os
|
||||
|
||||
30
tests/data/a-b.c/1.yml
Normal file
30
tests/data/a-b.c/1.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
config:
|
||||
name: "request methods testcase with functions"
|
||||
variables:
|
||||
foo1: session_bar1
|
||||
base_url: "https://postman-echo.com"
|
||||
verify: False
|
||||
|
||||
teststeps:
|
||||
-
|
||||
name: get with params
|
||||
variables:
|
||||
foo1: bar1
|
||||
foo2: session_bar2
|
||||
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()}
|
||||
extract:
|
||||
session_foo2: "body.args.foo2"
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
- eq: ["body.args.foo1", "session_bar1"]
|
||||
- eq: ["body.args.sum_v", "3"]
|
||||
- eq: ["body.args.foo2", "session_bar2"]
|
||||
30
tests/data/a-b.c/2 3.yml
Normal file
30
tests/data/a-b.c/2 3.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
config:
|
||||
name: "reference testcase unittest for abnormal folder path"
|
||||
variables:
|
||||
foo1: session_bar1
|
||||
base_url: "https://postman-echo.com"
|
||||
verify: False
|
||||
|
||||
teststeps:
|
||||
-
|
||||
name: request with functions
|
||||
variables:
|
||||
foo1: override_bar1
|
||||
testcase: 1.yml
|
||||
export:
|
||||
- session_foo2
|
||||
-
|
||||
name: post form data
|
||||
variables:
|
||||
foo1: bar1
|
||||
request:
|
||||
method: POST
|
||||
url: /post
|
||||
headers:
|
||||
User-Agent: HttpRunner/${get_httprunner_version()}
|
||||
Content-Type: "application/x-www-form-urlencoded"
|
||||
data: "foo1=$foo1&foo2=$session_foo2"
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
- eq: ["body.form.foo1", "session_bar1"]
|
||||
- eq: ["body.form.foo2", "session_bar2"]
|
||||
0
tests/data/a-b.c/__init__.py
Normal file
0
tests/data/a-b.c/__init__.py
Normal file
13
tests/data/a-b.c/debugtalk.py
Normal file
13
tests/data/a-b.c/debugtalk.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from httprunner import __version__
|
||||
|
||||
|
||||
def get_httprunner_version():
|
||||
return __version__
|
||||
|
||||
|
||||
def sum_two(m, n):
|
||||
return m + n
|
||||
|
||||
|
||||
def get_variables():
|
||||
return {"foo1": "session_bar1"}
|
||||
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from httprunner import loader
|
||||
from httprunner.cli import main_run
|
||||
from httprunner.runner import HttpRunner
|
||||
|
||||
|
||||
@@ -28,3 +30,11 @@ class TestHttpRunner(unittest.TestCase):
|
||||
self.assertEqual(result.name, "request methods testcase: reference testcase")
|
||||
self.assertEqual(result.step_datas[0].name, "request with functions")
|
||||
self.assertEqual(len(result.step_datas), 2)
|
||||
|
||||
def test_run_testcase_with_abnormal_path(self):
|
||||
exit_code = main_run(["tests/data/a-b.c/2 3.yml"])
|
||||
self.assertEqual(exit_code, 0)
|
||||
self.assertTrue(os.path.exists("tests/data/a_b_c/__init__.py"))
|
||||
self.assertTrue(os.path.exists("tests/data/a_b_c/debugtalk.py"))
|
||||
self.assertTrue(os.path.exists("tests/data/a_b_c/T1_test.py"))
|
||||
self.assertTrue(os.path.exists("tests/data/a_b_c/T2_3_test.py"))
|
||||
|
||||
@@ -101,24 +101,16 @@ class TestUtils(unittest.TestCase):
|
||||
|
||||
def test_ensure_file_path_valid(self):
|
||||
self.assertEqual(
|
||||
ensure_file_path_valid(
|
||||
"examples/a-b.c/d f/hardcode.yml"
|
||||
),
|
||||
os.path.join(
|
||||
os.getcwd(), "examples/a_b_c/d_f/hardcode.yml"
|
||||
),
|
||||
ensure_file_path_valid("examples/a-b.c/d f/hardcode.yml"),
|
||||
os.path.join(os.getcwd(), "examples/a_b_c/d_f/hardcode.yml"),
|
||||
)
|
||||
self.assertEqual(
|
||||
ensure_file_path_valid("1/2B/3.yml"),
|
||||
os.path.join(os.getcwd(), "T1/T2B/T3.yml"),
|
||||
)
|
||||
self.assertEqual(
|
||||
ensure_file_path_valid(
|
||||
"examples/a-b.c/2B/hardcode.yml"
|
||||
),
|
||||
os.path.join(
|
||||
os.getcwd(), "examples/a_b_c/T2B/hardcode.yml"
|
||||
),
|
||||
ensure_file_path_valid("examples/a-b.c/2B/hardcode.yml"),
|
||||
os.path.join(os.getcwd(), "examples/a_b_c/T2B/hardcode.yml"),
|
||||
)
|
||||
self.assertEqual(
|
||||
ensure_file_path_valid("examples/postman_echo/request_methods/"),
|
||||
|
||||
Reference in New Issue
Block a user