mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
refactor: builtin upload file method
This commit is contained in:
@@ -1,54 +1,35 @@
|
||||
# NOTICE: Generated By HttpRunner. DO NOT EDIT!
|
||||
# FROM: examples/httpbin/upload.yml
|
||||
|
||||
from httprunner import HttpRunner, TConfig, TStep
|
||||
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
|
||||
|
||||
|
||||
class TestCaseUpload(HttpRunner):
|
||||
config = TConfig(
|
||||
**{
|
||||
"name": "test upload file with httpbin",
|
||||
"base_url": "${get_httpbin_server()}",
|
||||
"path": "examples/httpbin/upload_test.py",
|
||||
"variables": {},
|
||||
}
|
||||
)
|
||||
config = Config("test upload file with httpbin").base_url("${get_httpbin_server()}")
|
||||
|
||||
teststeps = [
|
||||
TStep(
|
||||
**{
|
||||
"name": "upload file",
|
||||
"variables": {
|
||||
Step(
|
||||
RunRequest("upload file")
|
||||
.with_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"]},
|
||||
],
|
||||
}
|
||||
}
|
||||
)
|
||||
.post("/post")
|
||||
.with_headers(**{"Content-Type": "${multipart_content_type($m_encoder)}"})
|
||||
.with_data("$m_encoder")
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_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"]},
|
||||
],
|
||||
}
|
||||
Step(
|
||||
RunRequest("upload file with keyword")
|
||||
.post("/post")
|
||||
.upload(**{"file": "test.env"})
|
||||
.validate()
|
||||
.assert_equal("status_code", 200)
|
||||
.assert_startswith("body.files.file", "UserName=test")
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user