コード例 #1
0
 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
コード例 #2
0
 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"))
コード例 #3
0
 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"]
コード例 #4
0
 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中存在刚放入的推小程序指令")
コード例 #5
0
 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
コード例 #6
0
def replace_data(case_data):
    """数据参数格式化"""
    #匹配规则
    r = "#(.+?)#"
    #判断匹配结果是否是None
    while re.search(r,case_data):
        # 匹配出第一个要替换的内容
        res = re.search(r,case_data)
        # 提取待替换的内容
        item = res.group()
        # 获取替换内容的数据项
        key = res.group(1)
        try:
            case_data = case_data.replace(item,ih.get_str("data",key))
        except NoOptionError:
            case_data = case_data.replace(item,str(getattr(ReplaceData,key)))

    return case_data
コード例 #7
0
    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"]))
コード例 #8
0
    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"]))
コード例 #9
0
def get_account():
    # 读conf.ini配置文件获取host
    return ih.get_str("account", option="account")
コード例 #10
0
def get_host():
    # 读conf.ini配置文件获取host
    return ih.get_str("url", option="url")
コード例 #11
0
        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


if __name__ == '__main__':
    s = SendEMailHandle()
    s.send_html(ih.get_str("email", "to_user"), ih.get_str("email", "content"),
                ih.get_str("email", "subject"),
                os.path.join(REPORTS_DIR, "2020-03-30.html"),
                ih.get_str("email", "file_name"))