mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 01:39:39 +08:00
fix: check upload depencencies ready
This commit is contained in:
@@ -46,20 +46,18 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from typing import Text, NoReturn
|
from typing import Text, NoReturn
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from httprunner.parser import parse_variables_mapping
|
from httprunner.parser import parse_variables_mapping
|
||||||
from httprunner.schema import TStep, FunctionsMapping
|
from httprunner.schema import TStep, FunctionsMapping
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import filetype
|
import filetype
|
||||||
from requests_toolbelt import MultipartEncoder
|
from requests_toolbelt import MultipartEncoder
|
||||||
except ImportError:
|
|
||||||
msg = """
|
UPLOAD_READY = True
|
||||||
uploader extension dependencies uninstalled, install first and try again.
|
except ModuleNotFoundError:
|
||||||
install with pip:
|
UPLOAD_READY = False
|
||||||
$ pip install requests_toolbelt filetype
|
|
||||||
"""
|
|
||||||
print(msg)
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_upload_step(step: TStep, functions: FunctionsMapping) -> "NoReturn":
|
def prepare_upload_step(step: TStep, functions: FunctionsMapping) -> "NoReturn":
|
||||||
@@ -88,6 +86,15 @@ def prepare_upload_step(step: TStep, functions: FunctionsMapping) -> "NoReturn":
|
|||||||
if not step.request.upload:
|
if not step.request.upload:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not UPLOAD_READY:
|
||||||
|
msg = """
|
||||||
|
uploader extension dependencies uninstalled, install first and try again.
|
||||||
|
install with pip:
|
||||||
|
$ pip install requests_toolbelt filetype
|
||||||
|
"""
|
||||||
|
logger.error(msg)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
params_list = []
|
params_list = []
|
||||||
for key, value in step.request.upload.items():
|
for key, value in step.request.upload.items():
|
||||||
step.variables[key] = value
|
step.variables[key] = value
|
||||||
@@ -104,8 +111,12 @@ def prepare_upload_step(step: TStep, functions: FunctionsMapping) -> "NoReturn":
|
|||||||
step.request.data = "$m_encoder"
|
step.request.data = "$m_encoder"
|
||||||
|
|
||||||
|
|
||||||
def multipart_encoder(**kwargs) -> MultipartEncoder:
|
def multipart_encoder(**kwargs):
|
||||||
""" initialize MultipartEncoder with uploading fields.
|
""" initialize MultipartEncoder with uploading fields.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MultipartEncoder: initialized MultipartEncoder object
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_filetype(file_path):
|
def get_filetype(file_path):
|
||||||
@@ -144,7 +155,14 @@ def multipart_encoder(**kwargs) -> MultipartEncoder:
|
|||||||
return MultipartEncoder(fields=fields_dict)
|
return MultipartEncoder(fields=fields_dict)
|
||||||
|
|
||||||
|
|
||||||
def multipart_content_type(m_encoder: MultipartEncoder) -> Text:
|
def multipart_content_type(m_encoder) -> Text:
|
||||||
""" prepare Content-Type for request headers
|
""" prepare Content-Type for request headers
|
||||||
|
|
||||||
|
Args:
|
||||||
|
m_encoder: MultipartEncoder object
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
content type
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return m_encoder.content_type
|
return m_encoder.content_type
|
||||||
|
|||||||
Reference in New Issue
Block a user