Example #1
0
class SendMail:
    def __init__(self):
        self.config = Config()
        self.log = log.MyLog()

    def sendMail(self):
        msg = MIMEMultipart()
        stress_body = consts.STRESS_LIST
        result_body = consts.RESULT_LIST
        body2 = 'Hi,all\n本次接口自动化测试报告如下:\n   接口响应时间集:%s\n   接口运行结果集:%s' % (
            stress_body, result_body)
        mail_body2 = MIMEText(body2, _subtype='plain', _charset='utf-8')
        tm = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
        msg['Subject'] = Header("接口自动化测试报告" + "_" + tm, 'utf-8')
        msg['From'] = self.config.get_conf("email", "sender")
        receivers = self.config.get_conf("email", "receiver")
        toclause = receivers.split(',')
        msg['to'] = ",".join(toclause)

        msg.attach(mail_body2)

        try:
            smtp = smtplib.SMTP()
            smtp.connect(self.config.get_conf("email", "smtpserver"), 25)
            smtp.login(self.config.get_conf("email", "username"),
                       self.config.get_conf("email", "password"))
            smtp.sendmail(self.config.get_conf("email", "sender"), toclause,
                          msg.as_string())
        except Exception as e:
            print(e)
            self.log.error("邮件发送失败,请检查邮件配置")
        else:
            self.log.info("邮件发送成功")
        finally:
            smtp.quit()
Example #2
0
class RedisDb:
    config = Config()
    redisConf = config.redis_conf()

    # 链接Redis
    connection = redis.Redis(host=redisConf['host'],
                             port=redisConf['port'],
                             db=0,
                             password=redisConf['password'])
Example #3
0
def action():
    #定义环境
    env = Consts.API_ENVIRONMENT_RELEASE
    conf = Config()
    host = conf.host_relese
    tester = conf.tester_release
    allure.environment(environment=env)
    allure.environment(hostname=host)
    allure.environment(tester=tester)

    return env
Example #4
0
class Db:
    config = Config()
    # 获取数据库配置
    dbConf = config.db_conf()
    # 初始化数据库连接:
    query = 'mysql+mysqlconnector://' + dbConf['user'] + ':' + dbConf['password'] + '@' + dbConf['host'] + ':' + \
            dbConf['port'] + '/' + dbConf['db']
    # 链接数据库
    engine = create_engine(query)
    # 创建DBSession类型:
    DBSession = sessionmaker(bind=engine)
    # 创建Session:
    session = DBSession()

    # 查询hlh_giftcard,hlh_giftcardexchg数据
    def select_gift_card(self, info):
        # 创建Query查询,filter是where条件,最后调用one()返回唯一行,如果调用all()则返回所有行:
        giftCard = self.session.query(HlhGiftcard, HlhGiftcardexchg).outerjoin(
            HlhGiftcardexchg,
            HlhGiftcard.ID == HlhGiftcardexchg.GiftCardID).filter(
                HlhGiftcard.ID == int(info)).one()
        return giftCard

    # 查询hlh_mnssetting数据
    def select_mnssetting(self, info):
        mnsSetting = self.session.query(HlhMnssetting).filter(
            HlhMnssetting.MNSCode == int(info)).one()
        return mnsSetting

    # 插入数据hlh_mnssublog
    def insert_mnssublog(self, info, sendMsg):
        # 创建新HlhMnssublog对象:
        new_mnssublog = HlhMnssublog(MNSPubID=int(info['TopicID']),
                                     MNSSubID=int(info['MNSCode']),
                                     SubDate=time.strftime(
                                         '%Y%m%d%H%I%S',
                                         time.localtime(time.time())),
                                     SubContent=sendMsg['SubContent'],
                                     SubStatus=sendMsg['SubStatus'],
                                     ErrContent=sendMsg['ErrContent'])
        # 添加到session:
        self.session.add(new_mnssublog)
        # 提交即保存到数据库:
        self.session.commit()

    # 查询方案名
    def select_schema(self, info):
        schmName = self.session.query(
            HlhSchema.SchmName).filter(HlhSchema.ID == info).one()
        return schmName[0]

    # 关闭Session
    def finish(self):
        self.session.close()
Example #5
0
    def test_basic_02(self, action):
        """
            用例描述:登陆状态下查看基础设置
        """
        conf = Config()
        data = Basic()
        test = Assert.Assertions()
        request = Request.Request(action)

        host = conf.host_debug
        req_url = 'http://' + host
        urls = data.url
        params = data.data
        headers = data.header

        api_url = req_url + urls[1]
        response = request.post_request(api_url, params[1], headers[1])

        assert test.assert_code(response['code'], 401)
        assert test.assert_text(response['text'], '{"error":"继续操作前请注册或者登录."}')
        Consts.RESULT_LIST.append('True')
Example #6
0
    def test_basic_01(self, action):
        """
            用例描述:未登陆状态下查看基础设置
        """
        conf = Config()
        data = Basic()
        test = Assert.Assertions()
        request = Request.Request(action)

        host = conf.host_debug
        req_url = 'http://' + host
        urls = data.url
        params = data.data
        headers = data.header

        api_url = req_url + urls[0]
        response = request.get_request(api_url, params[0], headers[0])

        assert test.assert_code(response['code'], 401)
        assert test.assert_body(response['body'], 'error', u'继续操作前请注册或者登录.')
        assert test.assert_time(response['time_consuming'], 100)
        Consts.RESULT_LIST.append('True')
Example #7
0
 def __init__(self):
     self.config=Config()
     self.log=Log.MyLog()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
sys.path.append(
    "E:\Python\Redis-publishes-subscriptions")  # 导入自己编写的模块,填入项目模块对应存放路径
from Model.redisDb import *
import json
import logging
from Model.db import *
from Mail.htmlemail import *
from Conf.config import Config  # 引入配置文件

config = Config()
redisConf = config.redis_conf()

# 链接Redis
r = RedisDb().connection

# 订阅频道应该要和发布的频道一样,否则将无法订阅到发布者发布的消息
# 这里订阅了配置文件中的所有频道
channel = redisConf['channel']

# 创建监听实例
msg_queue = r.pubsub()

# 监听channel频道
msg_queue.subscribe(channel)

# 订阅监听
for msg in msg_queue.listen():
    if msg['type'] == 'message':
    def sed_email(self, giftCard, exchg, mnsSetting):
        # 创建配置对象,获取email信息
        config = Config()
        emailConf = config.email_conf()

        # 拼接V卡信息、兑换信息、订阅频道信息,构建HTML邮件内容
        msg = MIMEText(
            '''<!doctype html>
                            <html lang="zh">
                                <head>
                                    <meta charset="UTF-8" />
                                    <title></title>
                                    <meta http-equiv="X-UA-Compatible" content="IE=edge">
                                    <meta name="viewport" content="width=device-width, initial-scale=1">
                                    <style type="text/css">
                                        table {
                                            border: 1px solid #ddd;
                                            border-collapse: collapse;
                                            border-spacing: 0;
                                            empty-cells: show;
                                            margin-bottom: 8px;
                                            outline: 0;
                                            background-color: transparent;
                                            box-sizing: border-box;
                                            color: #333;
                                            font-size: 15px;
                                            width: 80%;
                                            margin-left: 10%;
                                        }
                                        th {
                                            vertical-align: middle;
                                            text-align: right;
                                            font-weight: 500;
                                            padding: 5px 0;
                                        }
                                        td {
                                            vertical-align: middle;
                                            font-weight: 500;
                                            padding: 5px 0;
                                        }
                                        caption {
                                            margin: 0;
                                            padding: 5px 6px;
                                            color: #fff;
                                            background-color: #337ab7;
                                            border-top-left-radius: 3px;
                                            border-top-right-radius: 3px;
                                            text-align: left;
                                            font-size: 16px;
                                        }
                                        @media only screen and (max-width: 768px) {
                                            table {
                                                width: 100%;
                                            }
                                            th {
                                                padding: 5px 0px;
                                                font-size: 10px;
                                                width: 32%;
                                            }
                                            td {
                                                font-size: 10px;
                                            }
                                            caption {
                                                padding: 2px 8px;
                                                font-size: 13px;
                                            }
                                        }
                                    </style>
                                </head>
                                <body>
                                    <table border="1">
                                        <caption>V卡详情</caption>
                                        <tr>
                                            <th width="15%">客户名:</th>
                                            <td width="35%">''' +
            str(giftCard.CustomerName) + '''</td>
                                            <th width="15%">V卡ID:</th>
                                            <td width="35%">''' +
            str(giftCard.ID) + '''</td>
                                        </tr>
                                        <tr>
                                            <th>卡号:</th>
                                            <td>''' + str(giftCard.CardNO) +
            '''</td>
                                            <th>创建人:</th>
                                            <td>''' + str(giftCard.CreateBy) +
            '''</td>
                                        </tr>
                                        <tr>
                                            <th>创建时间:</th>
                                            <td>''' +
            str(giftCard.CreateDate) + '''</td>
                                            <th>方案:</th>
                                            <td>''' + str(giftCard.schmName) +
            '''</td>
                                        </tr>
                                        <tr>
                                            <th>激活人:</th>
                                            <td>''' + str(giftCard.ActiveBy) +
            '''</td>
                                            <th>兑换码:</th>
                                            <td>''' + str(giftCard.ExchgCode) +
            '''</td>
                                        </tr>
                                        <tr>
                                            <th>激活时间:</th>
                                            <td>''' +
            str(giftCard.ActiveDate) + '''</td>
                                            <th>激活状态:</th>
                                            <td>''' +
            ('''已激活''' if str(giftCard.IsActive) == 'Y' else '''未激活''') +
            '''</td>
                                        </tr>
                                        <tr>
                                            <th>兑换状态:</th>
                                            <td colspan="3">''' +
            ('''已兑换''' if str(giftCard.IsExchg) == 'Y' else '''未兑换''') +
            '''</td>
                                        </tr>
                                    </table>
                                    <table border="1">
                                        <caption>兑换详情</caption>
                                        <tr>
                                            <th width="15%">兑换ID:</th>
                                            <td width="35%">''' +
            str(exchg.ID) + '''</td>
                                            <th width="15%">兑换商品编号:</th>
                                            <td width="35%"></td>
                                        </tr>
                                        <tr>
                                            <th>收货人姓名:</th>
                                            <td>''' + str(exchg.ShippingBy) +
            '''</td>
                                            <th>商品名称:</th>
                                            <td>''' + str(exchg.ProductName) +
            '''</td>
                                        </tr>
                                        <tr>
                                            <th>手机号:</th>
                                            <td>''' + str(exchg.MobileNO) +
            '''</td>
                                            <th>供应商:</th>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <th>收货地址:</th>
                                            <td>''' + exchg.Province +
            exchg.City + exchg.Area + exchg.ShippingAdress + '''</td>
                                            <th rowspan="4">商品图:</th>
                                            <td rowspan="4"><img width="180"/></td>
                                        </tr>
                                        <tr>
                                            <th>物流公司:</th>
                                            <td>''' +
            str(exchg.ExpressCompanyName) + '''</td>
                                        </tr>
                                        <tr>
                                            <th>快递单号:</th>
                                            <td>''' + str(exchg.ShipOrderNo) +
            '''</td>
                                        </tr>
                                        <tr>
                                            <th>发货人:</th>
                                            <td>''' + str(exchg.ShippingTo) +
            '''</td>
                                        </tr>
                                    </table>
                                </body>
                            </html>''', 'html', 'utf-8')
        # 添加邮件发件人
        msg['From'] = self._format_addr(
            '%s <%s>' % (emailConf['sender'], emailConf['username']))
        # 添加邮件收件人
        msg['To'] = self._format_addr('尊敬的客户 <%s>' % self.to_addr)
        # 添加邮件主题
        msg['Subject'] = Header(mnsSetting.MNSName, 'utf-8').encode()
        try:
            server = smtplib.SMTP(emailConf['stmp'], emailConf['port'])
            server.ehlo()
            # 创建SSL安全连接
            server.starttls()
            server.set_debuglevel(1)
            server.login(emailConf['username'], emailConf['password'])
            server.sendmail(emailConf['username'], self.to_addr,
                            msg.as_string())
            server.quit()
            sendMsg = {
                'SubStatus': 'Y',
                'SubContent': '{"status":"Y",content:"邮件发送成功"}',
                'ErrContent': ''
            }
            return sendMsg
        except smtplib.SMTPException as e:
            sendMsg = {
                'SubStatus': 'N',
                'SubContent': '{"status":"N",content:"邮件发送失败"}',
                'ErrContent': json.dumps(e)
            }
            return sendMsg