42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
# -*- coding:utf-8 -*-
|
||
|
||
"""
|
||
Author: qiaoxinjiu
|
||
Create Data: 2020/9/21 18:39
|
||
"""
|
||
import json
|
||
|
||
|
||
def check_resp(is_check, resp):
|
||
if is_check:
|
||
assert resp["code"] == 200, "{}, exp code: {}".format(resp, 200)
|
||
assert resp["success"] is True, "{}, exp code: {}".format(resp, True)
|
||
assert resp["message"] == "", "{}, exp code: {}".format(resp, "")
|
||
assert resp["data"] != "", "{}, exp code: {}".format(resp, "")
|
||
|
||
|
||
def custom_check_resp(is_check, assert_list):
|
||
"""传参数例子:asert_list = [(f"{resp}['code']", 0), (f"{resp}['message']", ""), (f"{resp}['success']", "True")]"""
|
||
if is_check:
|
||
for al in assert_list:
|
||
assert str(eval(al[0])) == str(al[1]), "{}, exp code: {}".format(eval(al[0]), al[1])
|
||
else:
|
||
pass
|
||
|
||
|
||
def convert_json(parames):
|
||
temp_json = json.dumps(parames)
|
||
temp_json1 = temp_json.replace("\"NULL\"", "null")
|
||
kwargs = json.loads(temp_json1)
|
||
|
||
return kwargs
|
||
|
||
|
||
def get_user(kwargs):
|
||
if kwargs.get("user", None):
|
||
user = kwargs.pop("user")
|
||
else:
|
||
user = None
|
||
|
||
return user, kwargs
|