mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
add custom functions: gen_urlencode_str, get_timestamp
This commit is contained in:
+1
-1
@@ -130,7 +130,7 @@ class HttpSession(requests.Session):
|
|||||||
method=method, url=url, exception=str(e)))
|
method=method, url=url, exception=str(e)))
|
||||||
else:
|
else:
|
||||||
logging.info(
|
logging.info(
|
||||||
""" status_code: {}! response_time: {} ms, response_length: {} bytes"""\
|
""" status_code: {}, response_time: {} ms, response_length: {} bytes"""\
|
||||||
.format(request_meta["status_code"], request_meta["response_time"], \
|
.format(request_meta["status_code"], request_meta["response_time"], \
|
||||||
request_meta["content_size"]))
|
request_meta["content_size"]))
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ import hashlib
|
|||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
string_type = basestring
|
string_type = basestring
|
||||||
PYTHON_VERSION = 2
|
PYTHON_VERSION = 2
|
||||||
|
import urllib
|
||||||
except NameError:
|
except NameError:
|
||||||
string_type = str
|
string_type = str
|
||||||
PYTHON_VERSION = 3
|
PYTHON_VERSION = 3
|
||||||
|
import urllib.parse as urllib
|
||||||
|
|
||||||
|
|
||||||
def gen_random_string(str_len):
|
def gen_random_string(str_len):
|
||||||
@@ -40,3 +43,30 @@ def handle_req_data(data):
|
|||||||
data = json.dumps(data, sort_keys=True)
|
data = json.dumps(data, sort_keys=True)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def gen_urlencode_str(**kargs):
|
||||||
|
urlencoded_str = ""
|
||||||
|
quote_times = int(kargs.pop("quote_times", 1))
|
||||||
|
|
||||||
|
for key, value in kargs.items():
|
||||||
|
urlencoded_str += key
|
||||||
|
urlencoded_str += "="
|
||||||
|
if value == "undefined":
|
||||||
|
urlencoded_str += "undefined"
|
||||||
|
else:
|
||||||
|
if isinstance(value, (dict, list)):
|
||||||
|
value = json.dumps(value)
|
||||||
|
elif isinstance(value, (int, float)):
|
||||||
|
value = str(value)
|
||||||
|
|
||||||
|
value_str = value.encode('utf-8')
|
||||||
|
for _ in range(quote_times):
|
||||||
|
value_str = urllib.quote_plus(value_str)
|
||||||
|
urlencoded_str += value_str
|
||||||
|
|
||||||
|
urlencoded_str += "&"
|
||||||
|
|
||||||
|
return urlencoded_str.strip("&")
|
||||||
|
|
||||||
|
def get_timestamp():
|
||||||
|
return int(time.time() * 1000)
|
||||||
|
|||||||
Reference in New Issue
Block a user