def login_in_status(sess): url = ReadConfig().get_base_url() + "/eshop/pc/crmMember/login" data = {"loginName": Login_User, "password": Login_Password} cookie_jar = sess.post(url=url, json=data) cookie = cookie_jar.cookies cookie_t = requests.utils.dict_from_cookiejar(cookie) # 把cookis对象 转成字典 return cookie_t
def conne_db(self): host = ReadConfig().get_db("host") port = ReadConfig().get_db("port") user = ReadConfig().get_db("user") password = ReadConfig().get_db("password") db = ReadConfig().get_db("db") sql = ReadConfig().get_db("sql") print(host, port, user, password, db, sql) connect = pymysql.Connect(host=host, port=int(port), user=user, password=password, db=db, charset='utf8', cursorclass=pymysql.cursors.DictCursor) cursor = connect.cursor() cursor.execute(sql) data = cursor.fetchone() print(data) print(data["total_consumption"])
import unittest import requests import os, sys from conf.readConfig import ReadConfig parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, parentdir) #读取配置文件 test_http_url = ReadConfig().get_url("test_http_url") dev_http_url = ReadConfig().get_url("dev_http_url") class AddLoginTest(unittest.TestCase): '''登录直连天下后台-test环境''' def setUp(self): self.base_url = test_http_url + "admin/base/login" print(self.base_url) def tearDown(self): print(self.result) def test_add_login_para_all_null(self): '''所有参数为空''' payload = {'username': '', 'password': '', 'isRemember': ''} r = requests.post(self.base_url, data=payload) self.result = r.json() self.assertEqual(self.result['code'], 400) self.assertEqual(self.result['data'], '') self.assertEqual(self.result['error'], '帐号不能为空')
import unittest from toolclass.sign import Sign from conf.readConfig import ReadConfig import requests test_xiadan_url = ReadConfig().get_url("test_xiadan_url") class PlaceOrderTest(unittest.TestCase): def setUp(self): self.http_url = test_xiadan_url + "recharge/order" self.sign = Sign().sign() def test_oder(self): accounType = self.sign[0] merchanId = self.sign[1] outTradeNo = self.sign[2] productId = self.sign[3] rechargeAccount = self.sign[4] time = self.sign[5] sign = self.sign[6].upper() # sign1 =sign.upper() # print(accounType,merchanId,outTradeNo,productId,rechargeAccount,time,sign) payload = { "merchantId": merchanId, "outTradeNo": outTradeNo, "productId": productId, "rechargeAccount": rechargeAccount, "accountType": accounType, "timeStamp": time, "sign": sign
from lib.md5_hash import Md5_Hash from conf.readConfig import ReadConfig from toolclass import time_samp,random_number timesamp = time_samp.time_samp() random_number = random_number.random_number() merchantId = ReadConfig().get_place_order("merchantId") outTradeNo = ReadConfig().get_place_order("outTradeNo") + str(random_number) productId = ReadConfig().get_place_order("productId") rechargeAccount = ReadConfig().get_place_order("rechargeAccount") accountType = ReadConfig().get_place_order("accountType") timeStamp = timesamp key = ReadConfig().get_place_order("key") class Sign(): def __init__(self): self.md5_hash = Md5_Hash().hash_md5 def sign(self): data = { "accountType":accountType, "merchantId":merchantId, "outTradeNo":outTradeNo, "productId":productId, "rechargeAccount":rechargeAccount, "timeStamp":str(timesamp), "key":key } print(sorted(data.keys()))
def send_request(s, data, cookie = None): """发送请求""" method = data["method"] url = ReadConfig().get_base_url() + data["url"] # 把congfig文件的路由地址和路径组成完整的URL try: params = eval(data["params"]) except Exception as msg: params = None logger.logger.warning(msg) try: header = eval(data["header"]) # print("header:%s" % header) if cookie != None: header = dict(header, **cookie) # header.update(cookie) except Exception as msg: header = None logger.logger.warning(msg) test_nub = data['case_id'] print("*******正在执行用例: %s ---- module:%s ********** %s" % (test_nub,data["module"], data["description"])) print("请求方式:%s, 请求url:%s" % (method, url)) print("请求头: %s" % header) print("请求params:%s" % params) # post请求body类型 type1 = data["type"] # try: # # bodydata = eval(data["data"]) # bodydata = ast.literal_eval(data["data"]) # # except Exception as msg: # bodydata = {} # logger.logger.warning(msg) # try: bodydata = json.loads(data["data"]) except Exception as e: bodydata = {} logger.logger.warning(e) # 判断传data数据还是json if type1 == "data": body = bodydata elif type1 == "json": body = json.dumps(bodydata) else: body = bodydata print("请求body:%s" % json.loads(body)) verify = False res = {} # 接受返回数据 try: res["case_id"] = data["case_id"] res['rowNum'] = data['rowNum'] # print(method, url, params, header, body) # verify禁用安全请求警告 response = s.request(method=method, url=url, params=params, headers=header, data=body, verify=verify) #todo: res["statuscode"] = str(response.status_code) # 状态码转成str #页面请求失败还是返回状态码200(未解决 print("expect:", data["expect"]) print("statuscode:", res["statuscode"]) res["text"] = response.content.decode("utf-8") res["times"] = str(response.elapsed.total_seconds()) # 接口请求时间转str if res["statuscode"] != "200": res["error"] = res["text"] else: res["error"] = "" res["msg"] = "" if data['expect'] in res['text']: res["result"] = "pass" print("用例测试结果: %s---->%s" % (test_nub, res["result"])) else: res['result'] = "fail" print("用例测试结果: %s---->%s" % (test_nub, res["result"])) if res['result'] == "fail": res["output"] = response.text print("returnData:", res["output"], type(res["output"])) else: res["output"] = "" return res except Exception as msg: res['msg'] = str(msg) logger.logger.exception(sys.exc_info()) print('msg:', msg) return res
def login_out_status(sess): url = ReadConfig().get_base_url() + "/eshop/pc/crmMember/logout" cookie_jar = sess.post(url=url)