feat: implement upload keyword

This commit is contained in:
debugtalk
2020-05-16 16:33:22 +08:00
parent a971c164ee
commit add392adf3
12 changed files with 384 additions and 41 deletions

View File

@@ -0,0 +1,89 @@
config:
name: basic test with httpbin
base_url: https://httpbin.org/
teststeps:
-
name: headers
request:
url: /headers
method: GET
validate:
- eq: ["status_code", 200]
- eq: [body.headers.Host, "httpbin.org"]
-
name: user-agent
request:
url: /user-agent
method: GET
validate:
- eq: ["status_code", 200]
# - startswith: [body.user-agent, "python-requests"]
-
name: get without params
request:
url: /get
method: GET
validate:
- eq: ["status_code", 200]
- eq: [body.args, {}]
-
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'}]
-
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'}]
-
name: set cookie
request:
url: /cookies/set?name=value
method: GET
validate:
- eq: ["status_code", 200]
# - eq: [cookies.name, "value"]
-
name: extract cookie
request:
url: /cookies
method: GET
validate:
- eq: ["status_code", 200]
# - eq: [cookies.name, "value"]
-
name: post data
request:
url: /post
method: POST
headers:
Content-Type: application/json
data: abc
validate:
- eq: ["status_code", 200]
-
name: validate body length
request:
url: /spec.json
method: GET
validate:
- len_eq: ["body", 9]

View File

@@ -0,0 +1,96 @@
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
from httprunner import HttpRunner, TConfig, TStep
class TestCaseBasic(HttpRunner):
config = TConfig(
**{
"name": "basic test with httpbin",
"base_url": "https://httpbin.org/",
"path": "examples/httpbin/basic_test.py",
}
)
teststeps = [
TStep(
**{
"name": "headers",
"request": {"url": "/headers", "method": "GET"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.headers.Host", "httpbin.org"]},
],
}
),
TStep(
**{
"name": "user-agent",
"request": {"url": "/user-agent", "method": "GET"},
"validate": [{"eq": ["status_code", 200]}],
}
),
TStep(
**{
"name": "get without params",
"request": {"url": "/get", "method": "GET"},
"validate": [{"eq": ["status_code", 200]}, {"eq": ["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"}]},
],
}
),
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"}]},
],
}
),
TStep(
**{
"name": "set cookie",
"request": {"url": "/cookies/set?name=value", "method": "GET"},
"validate": [{"eq": ["status_code", 200]}],
}
),
TStep(
**{
"name": "extract cookie",
"request": {"url": "/cookies", "method": "GET"},
"validate": [{"eq": ["status_code", 200]}],
}
),
TStep(
**{
"name": "post data",
"request": {
"url": "/post",
"method": "POST",
"headers": {"Content-Type": "application/json"},
"data": "abc",
},
"validate": [{"eq": ["status_code", 200]}],
}
),
TStep(
**{
"name": "validate body length",
"request": {"url": "/spec.json", "method": "GET"},
"validate": [{"len_eq": ["body", 9]}],
}
),
]
if __name__ == "__main__":
TestCaseBasic().test_start()

View File

@@ -0,0 +1,30 @@
config:
name: test upload file with httpbin
base_url: ${get_httpbin_server()}
teststeps:
-
name: upload file
variables:
file_path: "test.env"
m_encoder: ${multipart_encoder(file=$file_path)}
request:
url: /post
method: POST
headers:
Content-Type: ${multipart_content_type($m_encoder)}
data: $m_encoder
validate:
- eq: ["status_code", 200]
- startswith: ["body.files.file", "UserName=test"]
-
name: upload file with keyword
request:
url: /post
method: POST
upload:
file: "test.env"
validate:
- eq: ["status_code", 200]
- startswith: ["body.files.file", "UserName=test"]

View File

@@ -0,0 +1,54 @@
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
from httprunner import HttpRunner, TConfig, TStep
class TestCaseUpload(HttpRunner):
config = TConfig(
**{
"name": "test upload file with httpbin",
"base_url": "${get_httpbin_server()}",
"path": "examples/httpbin/upload_test.py",
}
)
teststeps = [
TStep(
**{
"name": "upload file",
"variables": {
"file_path": "test.env",
"m_encoder": "${multipart_encoder(file=$file_path)}",
},
"request": {
"url": "/post",
"method": "POST",
"headers": {
"Content-Type": "${multipart_content_type($m_encoder)}"
},
"data": "$m_encoder",
},
"validate": [
{"eq": ["status_code", 200]},
{"startswith": ["body.files.file", "UserName=test"]},
],
}
),
TStep(
**{
"name": "upload file with keyword",
"request": {
"url": "/post",
"method": "POST",
"upload": {"file": "test.env"},
},
"validate": [
{"eq": ["status_code", 200]},
{"startswith": ["body.files.file", "UserName=test"]},
],
}
),
]
if __name__ == "__main__":
TestCaseUpload().test_start()

View File

@@ -0,0 +1,35 @@
config:
name: basic test with httpbin
base_url: http://httpbin.org/
teststeps:
-
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"
-
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'"

View File

@@ -0,0 +1,43 @@
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
from httprunner import HttpRunner, TConfig, TStep
class TestCaseValidate(HttpRunner):
config = TConfig(
**{
"name": "basic test with httpbin",
"base_url": "http://httpbin.org/",
"path": "examples/httpbin/validate_test.py",
}
)
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"],
}
),
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'",
],
}
),
]
if __name__ == "__main__":
TestCaseValidate().test_start()