docs: update changelog and example tests

This commit is contained in:
debugtalk
2020-06-03 18:48:56 +08:00
parent 06912b75b1
commit b11d2b349d
8 changed files with 125 additions and 251 deletions

View File

@@ -1,12 +1,23 @@
# Release History
## 3.0.7 (2020-06-01)
## 3.0.7 (2020-06-03)
**Added**
- feat: make pytest files in chain style
**Fixed**
- fix: convert jmespath.search result to int/float unintentionally
- fix: referenced testcase should not be run duplicately
- fix: requests.cookies.CookieConflictError, multiple cookies with name
- fix: missing exit code from pytest
- fix: skip invalid testcase/testsuite yaml/json file
**Changed**
- change: generate pytest in chain style by default
- docs: update sponsor info
## 3.0.6 (2020-05-29)

View File

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

View File

@@ -1,105 +1,76 @@
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
# FROM: examples/httpbin/basic.yml
from httprunner import HttpRunner, TConfig, TStep
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
class TestCaseBasic(HttpRunner):
config = TConfig(
**{
"name": "basic test with httpbin",
"base_url": "https://httpbin.org/",
"path": "examples/httpbin/basic_test.py",
"variables": {},
}
)
config = Config("basic test with httpbin").base_url("https://httpbin.org/")
teststeps = [
TStep(
**{
"name": "headers",
"request": {"url": "/headers", "method": "GET"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.headers.Host", "httpbin.org"]},
],
}
Step(
RunRequest("headers")
.get("/headers")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.headers.Host", "httpbin.org")
),
TStep(
**{
"name": "user-agent",
"request": {"url": "/user-agent", "method": "GET"},
"validate": [
{"eq": ["status_code", 200]},
{"startswith": ['body."user-agent"', "python-requests"]},
],
}
Step(
RunRequest("user-agent")
.get("/user-agent")
.validate()
.assert_equal("status_code", 200)
.assert_startswith('body."user-agent"', "python-requests")
),
TStep(
**{
"name": "get without params",
"request": {"url": "/get", "method": "GET"},
"validate": [{"eq": ["status_code", 200]}, {"eq": ["body.args", {}]}],
}
Step(
RunRequest("get without params")
.get("/get")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.args", {})
),
TStep(
**{
"name": "get with params in url",
"request": {"url": "/get?a=1&b=2", "method": "GET"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args", {"a": "1", "b": "2"}]},
],
}
Step(
RunRequest("get with params in url")
.get("/get?a=1&b=2")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.args", {"a": "1", "b": "2"})
),
TStep(
**{
"name": "get with params in params field",
"request": {"url": "/get", "params": {"a": 1, "b": 2}, "method": "GET"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args", {"a": "1", "b": "2"}]},
],
}
Step(
RunRequest("get with params in params field")
.get("/get")
.with_params(**{"a": 1, "b": 2})
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.args", {"a": "1", "b": "2"})
),
TStep(
**{
"name": "set cookie",
"request": {"url": "/cookies/set?name=value", "method": "GET"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.cookies.name", "value"]},
],
}
Step(
RunRequest("set cookie")
.get("/cookies/set?name=value")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.cookies.name", "value")
),
TStep(
**{
"name": "extract cookie",
"request": {"url": "/cookies", "method": "GET"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.cookies.name", "value"]},
],
}
Step(
RunRequest("extract cookie")
.get("/cookies")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.cookies.name", "value")
),
TStep(
**{
"name": "post data",
"request": {
"url": "/post",
"method": "POST",
"headers": {"Content-Type": "application/json"},
"data": "abc",
},
"validate": [{"eq": ["status_code", 200]}],
}
Step(
RunRequest("post data")
.post("/post")
.with_headers(**{"Content-Type": "application/json"})
.with_data("abc")
.validate()
.assert_equal("status_code", 200)
),
TStep(
**{
"name": "validate body length",
"request": {"url": "/spec.json", "method": "GET"},
"validate": [{"len_eq": ["body", 9]}],
}
Step(
RunRequest("validate body length")
.get("/spec.json")
.validate()
.assert_length_equal("body", 9)
),
]

View File

@@ -1,48 +1,27 @@
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
# FROM: examples/httpbin/hooks.yml
from httprunner import HttpRunner, TConfig, TStep
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
class TestCaseHooks(HttpRunner):
config = TConfig(
**{
"name": "basic test with httpbin",
"base_url": "${get_httpbin_server()}",
"setup_hooks": ["${hook_print(setup)}"],
"teardown_hooks": ["${hook_print(teardown)}"],
"path": "examples/httpbin/hooks_test.py",
"variables": {},
}
)
config = Config("basic test with httpbin").base_url("${get_httpbin_server()}")
teststeps = [
TStep(
**{
"name": "headers",
"variables": {"a": 123},
"request": {"url": "/headers", "method": "GET"},
"setup_hooks": [
"${setup_hook_add_kwargs($request)}",
"${setup_hook_remove_kwargs($request)}",
],
"teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 1)}"],
"validate": [
{"eq": ["status_code", 200]},
{"contained_by": ["body.headers.Host", "${get_httpbin_server()}"]},
],
}
Step(
RunRequest("headers")
.with_variables(**{"a": 123})
.get("/headers")
.validate()
.assert_equal("status_code", 200)
.assert_contained_by("body.headers.Host", "${get_httpbin_server()}")
),
TStep(
**{
"name": "alter response",
"request": {"url": "/headers", "method": "GET"},
"teardown_hooks": ["${alter_response($response)}"],
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.headers.Host", "httpbin.org"]},
],
}
Step(
RunRequest("alter response")
.get("/headers")
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.headers.Host", "httpbin.org")
),
]

View File

@@ -1,47 +1,36 @@
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
# FROM: examples/httpbin/load_image.yml
from httprunner import HttpRunner, TConfig, TStep
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
class TestCaseLoadImage(HttpRunner):
config = TConfig(
**{
"name": "load images",
"base_url": "${get_httpbin_server()}",
"path": "examples/httpbin/load_image_test.py",
"variables": {},
}
)
config = Config("load images").base_url("${get_httpbin_server()}")
teststeps = [
TStep(
**{
"name": "get png image",
"request": {"url": "/image/png", "method": "GET"},
"validate": [{"eq": ["status_code", 200]}],
}
Step(
RunRequest("get png image")
.get("/image/png")
.validate()
.assert_equal("status_code", 200)
),
TStep(
**{
"name": "get jpeg image",
"request": {"url": "/image/jpeg", "method": "GET"},
"validate": [{"eq": ["status_code", 200]}],
}
Step(
RunRequest("get jpeg image")
.get("/image/jpeg")
.validate()
.assert_equal("status_code", 200)
),
TStep(
**{
"name": "get webp image",
"request": {"url": "/image/webp", "method": "GET"},
"validate": [{"eq": ["status_code", 200]}],
}
Step(
RunRequest("get webp image")
.get("/image/webp")
.validate()
.assert_equal("status_code", 200)
),
TStep(
**{
"name": "get svg image",
"request": {"url": "/image/svg", "method": "GET"},
"validate": [{"eq": ["status_code", 200]}],
}
Step(
RunRequest("get svg image")
.get("/image/svg")
.validate()
.assert_equal("status_code", 200)
),
]

View File

@@ -13,8 +13,8 @@ teststeps:
method: GET
validate:
- eq: ["status_code", 200]
- eq: ["body.args.a", 1]
- eq: ["body.args.b", 2]
- eq: ["body.args.a", "1"]
- eq: ["body.args.b", "2"]
validate_script:
- "assert status_code == 200"

View File

@@ -1,43 +1,28 @@
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
# FROM: examples/httpbin/validate.yml
from httprunner import HttpRunner, TConfig, TStep
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
class TestCaseValidate(HttpRunner):
config = TConfig(
**{
"name": "basic test with httpbin",
"base_url": "http://httpbin.org/",
"path": "examples/httpbin/validate_test.py",
"variables": {},
}
)
config = Config("basic test with httpbin").base_url("http://httpbin.org/")
teststeps = [
TStep(
**{
"name": "validate response with json path",
"request": {"url": "/get", "params": {"a": 1, "b": 2}, "method": "GET"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args.a", 1]},
{"eq": ["body.args.b", 2]},
],
"validate_script": ["assert status_code == 200"],
}
Step(
RunRequest("validate response with json path")
.get("/get")
.with_params(**{"a": 1, "b": 2})
.validate()
.assert_equal("status_code", 200)
.assert_equal("body.args.a", "1")
.assert_equal("body.args.b", "2")
),
TStep(
**{
"name": "validate response with python script",
"request": {"url": "/get", "params": {"a": 1, "b": 2}, "method": "GET"},
"validate": [{"eq": ["status_code", 200]}],
"validate_script": [
"assert status_code == 201",
"a = response_json.get('args').get('a')",
"assert a == '1'",
],
}
Step(
RunRequest("validate response with python script")
.get("/get")
.with_params(**{"a": 1, "b": 2})
.validate()
.assert_equal("status_code", 200)
),
]

View File

@@ -1,62 +0,0 @@
# NOTICE: Generated By HttpRunner.
import json
import os
import time
import pytest
from loguru import logger
from httprunner.utils import get_platform
@pytest.fixture(scope="session", autouse=True)
def session_fixture(request):
"""setup and teardown each task"""
logger.info(f"start running testcases ...")
start_at = time.time()
yield
logger.info(f"task finished, generate task summary for --save-tests")
summary = {
"success": True,
"stat": {
"testcases": {"total": 0, "success": 0, "fail": 0},
"teststeps": {"total": 0, "failures": 0, "successes": 0},
},
"time": {"start_at": start_at, "duration": time.time() - start_at},
"platform": get_platform(),
"details": [],
}
for item in request.node.items:
testcase_summary = item.instance.get_summary()
summary["success"] &= testcase_summary.success
summary["stat"]["testcases"]["total"] += 1
summary["stat"]["teststeps"]["total"] += len(testcase_summary.step_datas)
if testcase_summary.success:
summary["stat"]["testcases"]["success"] += 1
summary["stat"]["teststeps"]["successes"] += len(
testcase_summary.step_datas
)
else:
summary["stat"]["testcases"]["fail"] += 1
summary["stat"]["teststeps"]["successes"] += (
len(testcase_summary.step_datas) - 1
)
summary["stat"]["teststeps"]["failures"] += 1
summary["details"].append(testcase_summary.dict())
summary_path = "/Users/debugtalk/MyProjects/HttpRunner-dev/HttpRunner/examples/postman_echo/logs/request_methods/hardcode.summary.json"
summary_dir = os.path.dirname(summary_path)
os.makedirs(summary_dir, exist_ok=True)
with open(summary_path, "w", encoding="utf-8") as f:
json.dump(summary, f, indent=4)
logger.info(f"generated task summary: {summary_path}")