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

0
examples/data/.csv Normal file
View File

30
examples/data/a-b.c/1.yml Normal file
View File

@@ -0,0 +1,30 @@
config:
name: "request methods testcase with functions"
variables:
foo1: config_bar1
foo2: config_bar2
base_url: "https://postman-echo.com"
verify: False
teststeps:
-
name: get with params
variables:
foo1: bar1
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", "bar1"]
- eq: ["body.args.sum_v", "3"]
- eq: ["body.args.foo2", "config_bar2"]

View File

@@ -0,0 +1,26 @@
config:
name: "reference testcase unittest for abnormal folder path"
base_url: "https://postman-echo.com"
verify: False
teststeps:
-
name: request with functions
testcase: a-b.c/1.yml
export:
- session_foo2
-
name: post form data
variables:
foo1: bar12
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", "bar12"]
- eq: ["body.form.foo2", "config_bar2"]

View File

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

@@ -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"}

View File

@@ -0,0 +1,223 @@
{
"log": {
"version": "1.2",
"creator": {
"name": "Charles Proxy",
"version": "4.2.1"
},
"entries": [
{
"startedDateTime": "2018-02-19T17:30:00.904+08:00",
"time": 3,
"request": {
"method": "POST",
"url": "http://127.0.0.1:5000/api/get-token",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{
"name": "Host",
"value": "127.0.0.1:5000"
},
{
"name": "User-Agent",
"value": "python-requests/2.18.4"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Connection",
"value": "keep-alive"
},
{
"name": "device_sn",
"value": "FwgRiO7CNA50DSU"
},
{
"name": "user_agent",
"value": "iOS/10.3"
},
{
"name": "os_platform",
"value": "ios"
},
{
"name": "app_version",
"value": "2.8.6"
},
{
"name": "Content-Length",
"value": "52"
},
{
"name": "Content-Type",
"value": "application/json"
}
],
"queryString": [],
"postData": {
"mimeType": "application/json",
"text": "{\"sign\": \"958a05393efef0ac7c0fb80a7eac45e24fd40c27\"}"
},
"headersSize": 299,
"bodySize": 52
},
"response": {
"_charlesStatus": "COMPLETE",
"status": 200,
"statusText": "OK",
"httpVersion": "HTTP/1.0",
"cookies": [],
"headers": [
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Content-Length",
"value": "46"
},
{
"name": "Server",
"value": "Werkzeug/0.14.1 Python/3.6.4"
},
{
"name": "Date",
"value": "Mon, 19 Feb 2018 09:30:00 GMT"
},
{
"name": "Proxy-Connection",
"value": "Close"
}
],
"content": {
"size": 46,
"mimeType": "application/json",
"text": "eyJzdWNjZXNzIjogdHJ1ZSwgInRva2VuIjogImJhTkxYMXpoRllQMTFTZWIifQ\u003d\u003d",
"encoding": "base64"
},
"headersSize": 175,
"bodySize": 46
},
"serverIPAddress": "127.0.0.1",
"cache": {},
"timings": {
"dns": 1,
"connect": 0,
"ssl": -1,
"send": 0,
"wait": 1,
"receive": 1
}
},
{
"startedDateTime": "2018-02-19T17:30:00.911+08:00",
"time": 3,
"request": {
"method": "POST",
"url": "http://127.0.0.1:5000/api/users/1000",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{
"name": "Host",
"value": "127.0.0.1:5000"
},
{
"name": "User-Agent",
"value": "python-requests/2.18.4"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Connection",
"value": "keep-alive"
},
{
"name": "device_sn",
"value": "FwgRiO7CNA50DSU"
},
{
"name": "token",
"value": "baNLX1zhFYP11Seb"
},
{
"name": "Content-Length",
"value": "39"
},
{
"name": "Content-Type",
"value": "application/json"
}
],
"queryString": [],
"postData": {
"mimeType": "application/json",
"text": "{\"name\": \"user1\", \"password\": \"123456\"}"
},
"headersSize": 265,
"bodySize": 39
},
"response": {
"_charlesStatus": "COMPLETE",
"status": 201,
"statusText": "CREATED",
"httpVersion": "HTTP/1.0",
"cookies": [],
"headers": [
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Content-Length",
"value": "54"
},
{
"name": "Server",
"value": "Werkzeug/0.14.1 Python/3.6.4"
},
{
"name": "Date",
"value": "Mon, 19 Feb 2018 09:30:00 GMT"
},
{
"name": "Proxy-Connection",
"value": "Close"
}
],
"content": {
"size": 54,
"mimeType": "application/json",
"text": "eyJzdWNjZXNzIjogdHJ1ZSwgIm1zZyI6ICJ1c2VyIGNyZWF0ZWQgc3VjY2Vzc2Z1bGx5LiJ9",
"encoding": "base64"
},
"headersSize": 77,
"bodySize": 54
},
"serverIPAddress": "127.0.0.1",
"cache": {},
"timings": {
"dns": 0,
"connect": 0,
"ssl": -1,
"send": 0,
"wait": 3,
"receive": 0
}
}
]
}
}

View File

@@ -0,0 +1,148 @@
{
"log": {
"version": "1.2",
"creator": {
"name": "Charles Proxy",
"version": "4.2"
},
"entries": [
{
"startedDateTime": "2017-11-13T11:40:07.212+08:00",
"time": 35,
"request": {
"method": "POST",
"url": "https://httprunner.top/api/v1/Account/Login",
"httpVersion": "HTTP/1.1",
"cookies": [
{
"name": "lang",
"value": "zh"
}
],
"headers": [
{
"name": "Host",
"value": "httprunner.top"
},
{
"name": "Connection",
"value": "keep-alive"
},
{
"name": "Content-Length",
"value": "50"
},
{
"name": "Accept",
"value": "application/json"
},
{
"name": "Origin",
"value": "https://httprunner.top"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
},
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Referer",
"value": "https://httprunner.top/login"
},
{
"name": "Accept-Encoding",
"value": "gzip, deflate, br"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4"
}
],
"queryString": [],
"postData": {
"mimeType": "application/json",
"text": "{\"UserName\":\"test001\",\"Pwd\":\"123\",\"VerCode\":\"\"}"
},
"headersSize": 640,
"bodySize": 50
},
"response": {
"_charlesStatus": "COMPLETE",
"status": 200,
"statusText": "OK",
"httpVersion": "HTTP/1.1",
"cookies": [
{
"name": "lang",
"value": "zh",
"path": "/",
"domain": ".httprunner.top",
"expires": null,
"httpOnly": false,
"secure": false,
"comment": null,
"_maxAge": null
}
],
"headers": [
{
"name": "Date",
"value": "Mon, 13 Nov 2017 03:40:07 GMT"
},
{
"name": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"name": "Content-Length",
"value": "71"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Expires",
"value": "-1"
},
{
"name": "Server",
"value": "Microsoft-IIS/8.5"
},
{
"name": "X-AspNet-Version",
"value": "4.0.30319"
}
],
"content": {
"size": 71,
"mimeType": "application/json; charset=utf-8",
"text": "eyJJc1N1Y2Nlc3MiOnRydWUsIkNvZGUiOjIwMCwiTWVzc2FnZSI6bnVsbCwiVmFsdWUiOnsiQmxuUmVzdWx0Ijp0cnVlfX0=",
"encoding": "base64"
},
"redirectURL": null,
"headersSize": 0,
"bodySize": 71
},
"serverIPAddress": "192.168.1.169",
"cache": {},
"timings": {
"dns": -1,
"connect": -1,
"ssl": -1,
"send": 6,
"wait": 28,
"receive": 1
}
}
]
}
}

View File

@@ -0,0 +1,4 @@
headers:
Content-Type: "application/x-www-form-urlencoded"
cookies:
CASTGC: "TGT"

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