def delete_data(request): yield key = request.param sql1 = 'DELETE FROM wechat_auto_apply WHERE account = "dongfangyao"' sql2 = 'DELETE FROM wechat_heartbeat_history WHERE login_account = "dongfangyao"' sql3 = 'DELETE FROM wechat_friend WHERE wechat_id = "wxid_ss245739845"' sql4 = 'DELETE FROM wechat_auto_apply_friend_record WHERE wechat_id = "wxid_ss245739845"' sql5 = 'SELECT * FROM wechat_auto_apply WHERE account = "dongfangyao" ORDER BY id DESC' sql6 = 'SELECT * FROM wechat_heartbeat_history WHERE login_account = "dongfangyao" ORDER BY update_time DESC' sql7 = 'SELECT * FROM wechat_friend WHERE wechat_id = "wxid_ss245739845" ORDER BY id DESC' sql8 = 'SELECT * FROM wechat_auto_apply_friend_record WHERE wechat_id = "wxid_ss245739845" ORDER BY id DESC' mh.execute_sql(sql1) mh.execute_sql(sql2) mh.execute_sql(sql3) mh.execute_sql(sql4) # 清空redis中的指令 # key = Test_add_friend.teacher_wechat + "_{apply_friend_list}" # log.info("老师微信是:%s" % Test_add_friend.teacher_wechat) log.info(f"key值是:{key}") rh.delete(key) assert rh.list_getone(key) is None, "redis中存在指令:%s" % rh.list_getone(key) # if not mh.find_all(sql5) : # log.info(f"wechat_auto_apply表中存在数据:{mh.find_all(sql5)}") assert mh.find_all(sql5) == ( ), f"wechat_auto_apply表中存在数据:{mh.find_all(sql5)}" log.info("wechat_auto_apply表数据已经被清除") assert mh.find_all(sql6) == ( ), f"wechat_heartbeat_history表中存在数据:{mh.find_all(sql6)}" log.info("wechat_heartbeat_history表中数据已经被清除") assert mh.find_all(sql7) == (), f"wechat_friend表中存在数据:{mh.find_all(sql7)}" log.info("wechat_friend表中数据已经被清除") assert mh.find_all(sql8) == ( ), f"wechat_auto_apply_friend_record表中存在数据:{mh.find_all(sql8)}" log.info("wechat_auto_apply_friend_record表中数据已经被清除")
def send_text(self, to_user, content, subject): """ 发送文本邮件 :param to_user: 对方邮箱 :param content: 邮件正文 :param subject: 邮件主题 :return: """ # 第三步:准备邮件 # 使用email构造邮件 msg = MIMEText(content, _subtype='plain', _charset="utf8") # 添加发件人 msg["From"] = ih.get_str("email", "user") # 添加收件人 msg["To"] = to_user # 添加邮件主题 msg["subject"] = subject # 第四步:发送邮件 try: self._smtp_s.send_message(msg, from_addr=ih.get_str("email", "user"), to_addrs=to_user) log.info("------>>>邮件成功发送给:{},用时:{:.2f}s".format( to_user, (time.time() - self._t))) except smtplib.SMTPException as e: log.error("------>>>邮件发送给:{} 失败!用时:{:.2f}s".format( to_user, (time.time() - self._t))) log.error(e) assert e
def __init__(self): # 开始发送邮件时间 self._t = time.time() log.info("------>>>{}开始发送邮件------".format(ih.get_str("email", "user"))) # 第一步:连接到smtp服务器 self._smtp_s = smtplib.SMTP_SSL(host=ih.get_str("email", "host"), port=ih.get_int("email", "port")) # 第二步:登陆smtp服务器 self._smtp_s.login(user=ih.get_str("email", "user"), password=ih.get_str("email", "pwd"))
def test_login(self, case): username = case["username"] pwd = case["pwd"] expect = eval(case["expect"]) result = login(username, pwd) try: assert expect == result, "预期与实际结果不相符" log.info("用例执行成功") except AssertionError as e: log.error("用例执行失败") raise e
def test_mysql_wechat_push_minipro2(self): if Test_pushMiniPro.operationId == "": pytest.xfail(reason="心跳接口没有取到指令,验证status操作标记失败") sql = 'SELECT * FROM wechat_push_minipro WHERE account = "dongfangyao" ORDER BY id DESC ' result = mh.find_one(sql) log.info(f"wechat_auto_apply表中account=’dongfangyao‘的最新一条推送小程序数据是{result}") log.info(f"wechat_auto_apply表中recordId是{result[1]}") log.info(f"插入的recordId是{Test_pushMiniPro.recordId}") assert result[1] == Test_pushMiniPro.recordId, "最近一条数据的recordId是%s" % Test_pushMiniPro.recordId assert int(result[6]) == 0, "state字段是:%s" % result[7] log.info("wechat_auto_apply表中state值正确")
def send_html(self, to_user, content, subject, reports_path, file_name): """ 发送测试报告邮件 :param to_user: 对方邮箱 :param content: 邮件正文 :param subject: 邮件主题 :param reports_path: 测试报告路径 :param file_name: 发送时测试报告名称 """ # 读取报告文件中的内容 file_content = open(reports_path, "rb").read() # 2.使用email构造邮件 # (1)构造一封多组件的邮件 msg = MIMEMultipart() # (2)往多组件邮件中加入文本内容 text_msg = MIMEText(content, _subtype='plain', _charset="utf8") msg.attach(text_msg) # (3)往多组件邮件中加入文件附件 file_msg = MIMEApplication(file_content) file_msg.add_header('content-disposition', 'attachment', filename=file_name) msg.attach(file_msg) # 添加发件人 msg["From"] = ih.get_str("email", "user") # 添加收件人 msg["To"] = to_user # 添加邮件主题 msg["subject"] = subject # 第四步:发送邮件 try: self._smtp_s.send_message(msg, from_addr=ih.get_str("email", "user"), to_addrs=to_user) log.info("------>>>邮件成功发送给:{},用时:{:.2f}s".format( to_user, (time.time() - self._t))) except smtplib.SMTPException as e: log.error("------>>>邮件发送给:{} 失败!用时:{:.2f}s".format( to_user, (time.time() - self._t))) log.error(e) assert e
def test_send_pushMiniPro(self, get_host, get_account, create_recordId): """ 推推送小程序指令 :param get_host: :param get_account: :param create_recordId: :param create_remark: :param create_stuWechat: :return: """ # 读取host Test_pushMiniPro.host = get_host allure.attach("测试","测试1") # 读取accout Test_pushMiniPro.account = get_account # 得到推送小程序路径 self.pushMiniProUrl = ih.get_str("url", option="pushMiniPro") # 拼接完整url url = Test_pushMiniPro.host + self.pushMiniProUrl log.info(f"推小程序的接口地址是:{url}") # 获取recordID Test_pushMiniPro.recordId = create_recordId # 获取remark(不能重复) # Test_pushMiniPro.remark = create_remark # 读conf.ini配置文件获取stuWechat(最近一次推送小程序生成的stuWechat) Test_pushMiniPro.stuWechat = ih.get_str("stuWechat", option="stuWechat") # 读取teacher_wechat Test_pushMiniPro.teacher_wechat = ih.get_str("teacher_wechat", option="teacher_wechat") data = { "operationType": 36, "paramList": [ { "account": Test_pushMiniPro.account, "accountWechat": Test_pushMiniPro.teacher_wechat, "addParams": { "additionalProp1": "", "additionalProp2": "", "additionalProp3": "" }, "additionalInfo": "高意向学员", "guideSpeech": "同学你好", "miniproType": 0, "pictureImg": "string", "pictureTitle": "小程序", "programId": "ws123", "programURL": "http:hh123.com", "recordId": Test_pushMiniPro.recordId, "stuWechat": Test_pushMiniPro.stuWechat, "isFirstPriority": "0", "notNeedCover": "1", "notEnterCommonQueue": "false" } ], "source": "WE" } log.info(f"推小程序接口的入参是:{data}") log.info("开始发送推送小程序请求") response = myRequest.send(url=url, method="post", json=data) log.info(f"============接口响应结果:{response.json()}") # 将返回结果转成字典形式 result = response.json() log.info(f"状态码的值是: {response.status_code}") # 判断状态码=200 assert (response.status_code == 200), "判断状态码:response.status_code:%s 等于200" % response.status_code log.info("===状态码正确======") log.info("flag的值是: {flag}".format(flag=result["flag"])) # 判断flag是1 assert (int(result["flag"]) == 1), "判断flag:%s 等于1" % result["flag"] # 判断flag如果是0,打出具体的错误信息message if int(result["flag"]) == 0: err_log.error(r"------出现错误:message:{message}".format(message=result["message"]))
def test_operationCallback1(self): if Test_pushMiniPro.operationId == "": pytest.xfail(reason="心跳接口没有取到指令,operationCallback接口标记失败") # 得到operationCallback接口路径 self.operationCallback = ih.get_str("url", option="operationCallback") # 拼接完整url url = Test_pushMiniPro.host + self.operationCallback log.info(f"operationCallback接口的地址是:{url}") data = { "additionalInfo": "additionalInfo1", "operationId": Test_pushMiniPro.operationId, "operationType": Test_pushMiniPro.operationType, "recordId": Test_pushMiniPro.recordId, "state": 0, "system": "lsxtest", "wechatId": Test_pushMiniPro.teacher_wechat, "versionName": "3.1.13", "versionCode": "97", "wechatAccount": Test_pushMiniPro.teacher_wechat, "wechatVersion": "7.0.5", "wechatVersionCode": "1440", "source": "app_root", "loginAccount": Test_pushMiniPro.account, "phoneDeviceId": "2cd6f7c3b0a15b2f", "channel": "platform" } log.info(f"operationCallback1接口的入参是:{data}") log.info("=====开始请求operationCallback1接口") response = myRequest.send(url=url, method="post", json=data) log.info(f"============接口响应结果:{response.json()}") # 将返回结果转成字典形式 result = response.json() log.info(f"状态码的值是: {response.status_code}") # 判断状态码=200 assert (response.status_code == 200), "判断状态码:response.status_code:%s 等于200" % response.status_code log.info("===状态码正确======") # 判断flag是1 assert (int(result["flag"]) == 1), "判断flag:%s 等于1" % result["flag"] # 判断flag如果是0,打出具体的错误信息message if int(result["flag"]) == 0: err_log.error(r"------出现错误:message:{message}".format(message=result["message"]))
def test_heartbeat(self): """ 请求心跳接口取指令 :return: """ # 得到心跳接口路径 self.heartbeat = ih.get_str("url", option="heartbeat") # 拼接完整url url = Test_pushMiniPro.host + self.heartbeat log.info(f"心跳接口接口的地址是:{url}") data = { "account": Test_pushMiniPro.account, "canReceiveNewOrder": True, "isRoot": True, "laterReceive": False, "miPushId": "PFHBfYNju2pJ7970mm3OvnSiUgFIC\/d7wTctDTfP+3n5RXTnRn0Eyqes2yJaVzQm", "os": "android", "otherWechatIds": ["wxid_y2twb3cy6a3o22_YC"], "version": "3.1.9", "wechatDeviceId": "11ea23e764c1302a", "wechatId": Test_pushMiniPro.teacher_wechat, "wechatLive": True, "wechatVersion": "7.0.4", "wxBackgroundMode": True, "wxHackEnabled": True, "versionName": "3.0.6.1", "versionCode": "69", "wechatAccount": Test_pushMiniPro.teacher_wechat, "wechatVersionCode": "1420", "source": "app_root", "loginAccount": Test_pushMiniPro.account, "phoneDeviceId": "11ea23e764c1302a" } log.info(f"心跳接口的入参是:{data}") log.info("=====开始请求心跳接口") response = myRequest.send(url=url, method="post", json=data) log.info(f"============接口响应结果:{response.json()}") # 将返回结果转成字典形式 result = response.json() log.info(f"状态码的值是: {response.status_code}") # 判断状态码=200 assert (response.status_code == 200), "判断状态码:response.status_code:%s 等于200" % response.status_code log.info("===状态码正确======") log.info("operationId的值是: {operationId}".format(operationId=result["data"]["operationId"])) log.info(type(result["data"])) # 判断operationId是1 assert (int(result["data"]["operationId"]) != -1), "判断operationId:%s 不等于-1" % result["data"]["operationId"] # 得到心跳接口的operationId Test_pushMiniPro.operationId = result["data"]["operationId"] # 得到心跳接口的operationType Test_pushMiniPro.operationType = result["data"]["operationType"] # 得到心跳接口的recordId Test_pushMiniPro.recordId = result["data"]["recordId"] # 判断operationId如果是-1,打出具体的错误信息message if int(result["data"]["operationId"]) == -1: err_log.error(r"------出现错误:心跳接口没有取到指令") return result["data"]["operationId"]
def test_redis(self): Test_pushMiniPro.key = Test_pushMiniPro.teacher_wechat + ih.get_str("postfix", option="pushminipro") log.info("老师微信是:%s" % Test_pushMiniPro.teacher_wechat) log.info(f"key值是:{Test_pushMiniPro.key}") result = rh.list_getone(Test_pushMiniPro.key,0,0) assert result is not None, f"result的值是{result},队列里没有推小程序指令" log.info(f"最新放入redis的推小程序指令是:{result}") assert result["recordId"] == Test_pushMiniPro.recordId, "判断redis中最右侧的指令的recordId是:%s" % result["recordId"] log.info("redis中最新一条指令的recordId是:%s" % result["recordId"]) log.info("生成的recordId是:%s" % Test_pushMiniPro.recordId) log.info("redis中存在刚放入的推小程序指令")
def test_s2(login): log.info("成功") print("==用例2==") print(login)