refactor: relocate python test files

This commit is contained in:
debugtalk
2022-03-23 17:28:54 +08:00
parent 8ac27790b2
commit 64ff34a341
38 changed files with 127 additions and 43 deletions

View File

@@ -2,7 +2,6 @@
[![Github Actions](https://github.com/httprunner/httprunner/actions/workflows/unittest.yml/badge.svg)](https://github.com/httprunner/httprunner/actions)
[![codecov](https://codecov.io/gh/httprunner/httprunner/branch/master/graph/badge.svg)](https://codecov.io/gh/httprunner/httprunner)
[![Go Report Card](https://goreportcard.com/badge/github.com/httprunner/httprunner)](https://goreportcard.com/report/github.com/httprunner/httprunner)
[![Go Reference](https://pkg.go.dev/badge/github.com/httprunner/httprunner.svg)](https://pkg.go.dev/github.com/httprunner/httprunner)
[![downloads](https://pepy.tech/badge/httprunner)](https://pepy.tech/project/httprunner)
[![pypi version](https://img.shields.io/pypi/v/httprunner.svg)](https://pypi.python.org/pypi/httprunner)

View File

@@ -0,0 +1,36 @@
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: a-b.c/1.yml
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
class TestCaseT1(HttpRunner):
config = (
Config("request methods testcase with functions")
.variables(**{"foo1": "config_bar1", "foo2": "config_bar2"})
.base_url("https://postman-echo.com")
.verify(False)
)
teststeps = [
Step(
RunRequest("get with params")
.with_variables(**{"foo1": "bar1", "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.foo2", "session_foo2")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.args.foo1", "bar1")
.assert_equal("body.args.sum_v", "3")
.assert_equal("body.args.foo2", "config_bar2")
),
]
if __name__ == "__main__":
TestCaseT1().test_start()

View File

@@ -0,0 +1,46 @@
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: a-b.c/2 3.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 a_b_c.T1_test import TestCaseT1 as T1
class TestCaseT23(HttpRunner):
config = (
Config("reference testcase unittest for abnormal folder path")
.base_url("https://postman-echo.com")
.verify(False)
)
teststeps = [
Step(RunTestCase("request with functions").call(T1).export(*["session_foo2"])),
Step(
RunRequest("post form data")
.with_variables(**{"foo1": "bar12"})
.post("/post")
.with_headers(
**{
"User-Agent": "HttpRunner/${get_httprunner_version()}",
"Content-Type": "application/x-www-form-urlencoded",
}
)
.with_data("foo1=$foo1&foo2=$session_foo2")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.form.foo1", "bar12")
.assert_equal("body.form.foo2", "config_bar2")
),
]
if __name__ == "__main__":
TestCaseT23().test_start()

View File

@@ -0,0 +1 @@
# NOTICE: Generated By HttpRunner. DO NOT EDIT!

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.1.7
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: request_methods/request_with_functions.yml

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.1.7
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: request_methods/request_with_testcase_reference.yml

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.1.7
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: request_methods/hardcode.yml

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.1.7
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: request_methods/request_with_functions.yml

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.1.7
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: request_methods/request_with_parameters.yml

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.1.7
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: request_methods/request_with_testcase_reference.yml

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.1.7
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: request_methods/request_with_variables.yml

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.1.7
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: request_methods/validate_with_functions.yml

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By HttpRunner v3.1.7
# NOTE: Generated By HttpRunner v4.0.0-alpha
# FROM: request_methods/validate_with_variables.yml

View File

@@ -11,25 +11,25 @@ class TestCompat(unittest.TestCase):
def test_convert_variables(self):
raw_variables = [{"var1": 1}, {"var2": "val2"}]
self.assertEqual(
compat.convert_variables(raw_variables, "tests/data/a-b.c/1.yml"),
compat.convert_variables(raw_variables, "examples/data/a-b.c/1.yml"),
{"var1": 1, "var2": "val2"},
)
raw_variables = {"var1": 1, "var2": "val2"}
self.assertEqual(
compat.convert_variables(raw_variables, "tests/data/a-b.c/1.yml"),
compat.convert_variables(raw_variables, "examples/data/a-b.c/1.yml"),
{"var1": 1, "var2": "val2"},
)
raw_variables = "${get_variables()}"
self.assertEqual(
compat.convert_variables(raw_variables, "tests/data/a-b.c/1.yml"),
compat.convert_variables(raw_variables, "examples/data/a-b.c/1.yml"),
{"foo1": "session_bar1"},
)
with self.assertRaises(exceptions.TestCaseFormatError):
raw_variables = [{"var1": 1}, {"var2": "val2", "var3": 3}]
compat.convert_variables(raw_variables, "tests/data/a-b.c/1.yml")
compat.convert_variables(raw_variables, "examples/data/a-b.c/1.yml")
with self.assertRaises(exceptions.TestCaseFormatError):
compat.convert_variables(None, "tests/data/a-b.c/1.yml")
compat.convert_variables(None, "examples/data/a-b.c/1.yml")
def test_convert_jmespath(self):

View File

@@ -2,14 +2,15 @@ import os
from httprunner.ext.har2case.core import HarParser
from httprunner.ext.har2case.utils import load_har_log_entries
from tests.ext.har2case.har_utils_test import TestHar2CaseUtils
from httprunner.ext.har2case.utils_test import TestHar2CaseUtils
class TestHar(TestHar2CaseUtils):
def setUp(self):
self.har_path = os.path.join(os.path.dirname(__file__), "data", "demo.har")
self.data_dir = os.path.join(os.getcwd(), "examples", "data", "har2case")
self.har_path = os.path.join(self.data_dir, "demo.har")
self.har_parser = HarParser(self.har_path)
self.profile_path = os.path.join(os.path.dirname(__file__), "data", "profile.yml")
self.profile_path = os.path.join(self.data_dir, "profile.yml")
def test_prepare_teststep(self):
log_entries = load_har_log_entries(self.har_path)
@@ -35,14 +36,14 @@ class TestHar(TestHar2CaseUtils):
self.assertIn("validate", teststeps[0])
def test_gen_testcase_yaml(self):
yaml_file = os.path.join(os.path.dirname(__file__), "data", "demo.yml")
yaml_file = os.path.join(self.data_dir, "demo.yml")
self.har_parser.gen_testcase(file_type="YAML")
self.assertTrue(os.path.isfile(yaml_file))
os.remove(yaml_file)
def test_gen_testcase_json(self):
json_file = os.path.join(os.path.dirname(__file__), "data", "demo.json")
json_file = os.path.join(self.data_dir, "demo.json")
self.har_parser.gen_testcase(file_type="JSON")
self.assertTrue(os.path.isfile(json_file))
@@ -169,7 +170,7 @@ class TestHar(TestHar2CaseUtils):
def test_make_testcase(self):
har_path = os.path.join(
os.path.dirname(__file__), "data", "demo-quickstart.har"
self.data_dir, "demo-quickstart.har"
)
har_parser = HarParser(har_path)
testcase = har_parser._make_testcase()

View File

@@ -6,10 +6,13 @@ from httprunner.ext.har2case import utils
class TestHar2CaseUtils(unittest.TestCase):
data_dir = os.path.join(os.getcwd(), "examples", "data", "har2case")
@staticmethod
def create_har_file(file_name, content):
file_path = os.path.join(
os.path.dirname(__file__), "data", "{}.har".format(file_name)
TestHar2CaseUtils.data_dir, "{}.har".format(file_name)
)
with open(file_path, "w") as f:
f.write(json.dumps(content))
@@ -17,7 +20,7 @@ class TestHar2CaseUtils(unittest.TestCase):
return file_path
def test_load_har_log_entries(self):
har_path = os.path.join(os.path.dirname(__file__), "data", "demo.har")
har_path = os.path.join(TestHar2CaseUtils.data_dir, "demo.har")
log_entries = utils.load_har_log_entries(har_path)
self.assertIsInstance(log_entries, list)
self.assertIn("request", log_entries[0])

View File

@@ -41,7 +41,7 @@ class TestLoader(unittest.TestCase):
os.remove(json_tmp_file)
def test_load_testcases_bad_filepath(self):
testcase_file_path = os.path.join(os.getcwd(), "tests/data/demo")
testcase_file_path = os.path.join(os.getcwd(), "examples/data/demo")
with self.assertRaises(exceptions.FileNotFound):
loader.load_testcase_file(testcase_file_path)

View File

@@ -18,6 +18,7 @@ class TestMake(unittest.TestCase):
pytest_files_made_cache_mapping.clear()
pytest_files_run_set.clear()
loader.project_meta = None
self.data_dir = os.path.join(os.getcwd(), "examples", "data")
def test_make_testcase(self):
path = ["examples/postman_echo/request_methods/request_with_variables.yml"]
@@ -94,9 +95,9 @@ from request_methods.request_with_functions_test import (
def test_ensure_file_path_valid(self):
self.assertEqual(
ensure_file_abs_path_valid(
os.path.join(os.getcwd(), "tests", "data", "a-b.c", "2 3.yml")
os.path.join(self.data_dir, "a-b.c", "2 3.yml")
),
os.path.join(os.getcwd(), "tests", "data", "a_b_c", "T2_3.yml"),
os.path.join(self.data_dir, "a_b_c", "T2_3.yml"),
)
loader.project_meta = None
self.assertEqual(
@@ -117,30 +118,27 @@ from request_methods.request_with_functions_test import (
loader.project_meta = None
self.assertEqual(
ensure_file_abs_path_valid(
os.path.join(os.getcwd(), "tests", "data", ".csv")
os.path.join(self.data_dir, ".csv")
),
os.path.join(os.getcwd(), "tests", "data", ".csv"),
os.path.join(self.data_dir, ".csv"),
)
def test_convert_testcase_path(self):
self.assertEqual(
convert_testcase_path(
os.path.join(os.getcwd(), "tests", "data", "a-b.c", "2 3.yml")
os.path.join(self.data_dir, "a-b.c", "2 3.yml")
),
(
os.path.join(os.getcwd(), "tests", "data", "a_b_c", "T2_3_test.py"),
os.path.join(self.data_dir, "a_b_c", "T2_3_test.py"),
"T23",
),
)
self.assertEqual(
convert_testcase_path(
os.path.join(os.getcwd(), "tests", "data", "a-b.c", "中文case.yml")
os.path.join(self.data_dir, "a-b.c", "中文case.yml")
),
(
os.path.join(
os.getcwd(),
os.path.join("tests", "data", "a_b_c", "中文case_test.py"),
),
os.path.join(self.data_dir, "a_b_c", "中文case_test.py"),
"中文Case",
),
)

View File

@@ -32,9 +32,9 @@ class TestHttpRunner(unittest.TestCase):
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"])
exit_code = main_run(["examples/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/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"))
self.assertTrue(os.path.exists("examples/data/a_b_c/__init__.py"))
self.assertTrue(os.path.exists("examples/data/debugtalk.py"))
self.assertTrue(os.path.exists("examples/data/a_b_c/T1_test.py"))
self.assertTrue(os.path.exists("examples/data/a_b_c/T2_3_test.py"))

View File

@@ -3,14 +3,14 @@ name = "httprunner"
version = "4.0.0-alpha"
description = "One-stop solution for HTTP(S) testing."
license = "Apache-2.0"
readme = "docs/README.md"
readme = "README.md"
authors = ["debugtalk <debugtalk@gmail.com>"]
homepage = "https://github.com/httprunner/httprunner"
repository = "https://github.com/httprunner/httprunner"
documentation = "https://docs.httprunner.org"
documentation = "https://httprunner.com/docs"
keywords = ["HTTP", "api", "test", "requests", "locustio"]
keywords = ["HTTP", "apitest", "perftest", "DEM", "requests", "locustio"]
classifiers = [
"Development Status :: 5 - Production/Stable",

View File

View File

View File