Exemple #1
0
    def __init__(self, configfile):
        self.time = globalTime.getGlobalTime()
        self.filename = rootpath + relpath + self.time + '.xls'

        self.config = configparser.ConfigParser()
        self.config.read(configfile)
        self.host = self.config.get('MAIL', 'HOST')
        self.user = self.config.get('MAIL', 'USER')
        self.pwd = self.config.get('MAIL', 'PWD')
        self.receivers = self.config.get('MAIL', 'RECEIVERS')
        self.list = self.receivers.split(';')

        self.getClass = getMailContent.getMailContent()
        self.content = self.getClass.readAndJudge()
        self.getClass.closeRead()

        self.logger = writeLog.writeLogger(loglevel=4, logger="sendMail")
        if not self.getClass.getFlag():
            self.mailContent.append(
                "                        测试情况说明如下(具体情况请查看分析文件)\n")
        else:
            self.mailContent.append("                            测试情况说明如下 \n")

        for i in range(0, len(self.content)):
            self.mailContent.append(self.content[i])
        self.msg = '\n'.join(self.mailContent)

        self.mailContent.clear()
        self.getClass.clearVar()

        message = MIMEMultipart('related')
        message['From'] = formataddr(["Search Result", self.user])  # 发送者
        for i in range(0, len(self.list)):
            message['To'] = formataddr(
                ["{receiver}".format(receiver=self.list[i]),
                 self.list[i]])  # 接收者
        if not self.getClass.getFlag():
            self.flag = "Warning"
        else:
            self.flag = "Success"
        message['Subject'] = '{Date}自动测试报告-{state}'.format(Date=self.time,
                                                           state=self.flag)
        message.attach(MIMEText(self.msg, 'plain', 'utf-8'))
        if not self.getClass.getFlag():
            att = MIMEText(open(self.filename, 'rb').read(), 'base64', 'utf-8')
            att["Content-Type"] = 'application/octet-stream'
            att.add_header('Content-Disposition',
                           'attachment',
                           filename='分析文件.xls')
            message.attach(att)

        try:
            server = smtplib.SMTP_SSL(self.host, 465)
            server.login(self.user, self.pwd)
            server.sendmail(self.user, self.list, message.as_string())
            server.quit()
            self.logger.info("邮件发送成功")
        except Exception as e:
            self.logger.error("{Error}: 无法发送邮件".format(Error=e))
Exemple #2
0
 def __init__(self, configfile):
     self.config = configparser.ConfigParser()
     self.config.read(configfile)
     self.ip = self.config.get('MYSQL', 'IP')
     self.user = self.config.get("MYSQL", "UserName")
     self.pwd = self.config.get("MYSQL", "PassWord")
     self.dbname = self.config.get("MYSQL", "DBName")
     self.logger = writeLog.writeLogger(loglevel=4, logger="operationMysql")
     try:
         self.db = pymysql.connect(self.ip, self.user, self.pwd,
                                   self.dbname)
         self.logger.info("Mysql connect success!")
     except:
         self.logger.info("Mysql connect failure!")
Exemple #3
0
import sys
import os
path1 = os.path.abspath('..')
path2 = os.path.abspath(path1 + os.path.sep + '..')
sys.path.append(path2)

import Codes.Tools.writeLog as writeLog
import Codes.Script.singleThread as singleThread
import time
import Codes.Tools.getTime as getTime
import Codes.Script.globalTime as globalTime
log = writeLog.writeLogger(loglevel=4, logger="main")
while 1:
    try:
        thread = singleThread.singleThread(1, 'Main')
        thread.start()
        log.info("main执行成功!")
        thread.join()
        log.info("测试完成,退出主线程")
    except Exception as e:
        log.error(e)
        log.error("main执行失败!")
    time.sleep(86400)
    globalTime.setGlobalTime(getTime.getTime().getToHour())
Exemple #4
0
 def __init__(self):
     self.workbook = xlwt.Workbook()
     self.time = globalTime.getGlobalTime()
     self.reportname = rootpath + relpath + self.time + '.xls'
     self.logger = writeLog.writeLogger(loglevel=4, logger="writeExcel")
Exemple #5
0
 def __init__(self, filepath):
     self.o = readExcel.readExcel(filepath)
     self.work_book = self.o.excelfile
     self.logger = writeLog.writeLogger(loglevel=4, logger="getValues")
Exemple #6
0
 def __init__(self, excelconf):
     self.config = getValues.getValues(excelconf)
     self.logger = writeLog.writeLogger(loglevel=4, logger="autoTest")
     self.resl = ''
Exemple #7
0
 def __init__(self, request_info):
     self.info = request_info
     self.errormsg = []
     self.right = True
     self.logger = writeLog.writeLogger(loglevel=4, logger="analysisDate")
     self.errorcode = -2
    def __init__(self, request_info):
        self.logger = writeLog.writeLogger(loglevel=4, logger="requestData")
        # 模块名称
        self.module = request_info['module']
        # 接口名称
        self.name = request_info['name']
        # 接口英文名称
        self.name_en = request_info['name_en']
        # 超时
        if request_info['overtime'] and request_info['overtime'] != 0:
            self.overtime = int(request_info['overtime'])
        else:
            self.overtime = 30
        # 接口url
        self.url = request_info['url']
        # 接口请求方式
        self.operation = request_info['operation']
        # 参数
        arg_dict = request_info['arg_dict']
        self.arg_list = []

        # 今天日期
        today = datetime.date.today()
        # 昨天时间
        yesterday = today - datetime.timedelta(days=1)
        # 昨天开始时间戳
        yesterday_start_time = int(time.mktime(time.strptime(str(yesterday), '%Y-%m-%d')))
        # 今天开始时间戳
        today_start_time = int(time.mktime(time.strptime(str(today), '%Y-%m-%d')))

        for key in arg_dict:
            if key.lower() == 'begintime' or key.lower() == 'starttime':
                if arg_dict[key] == '':
                    if 'begin_offset' in request_info:
                        if request_info['begin_offset'] == '':
                            beginoffset = 0
                        else:
                            beginoffset = request_info['begin_offset']
                        yesterday_start_time = int(yesterday_start_time + beginoffset * 3600)

                    self.arg_list.append(key + '=' + str(yesterday_start_time))
                else:
                    if arg_dict[key].isdigit():
                        self.arg_list.append(key + '=' + arg_dict[key])
                    else:
                        begintimeArray = time.strptime(arg_dict[key], "%Y-%m-%d %H:%M:%S")
                        # 指定时间格式 "2018-07-20 16:28:54"
                        self.arg_list.append(key + '=' + str(time.mktime(begintimeArray)))
            elif key.lower() == 'endtime':
                if arg_dict[key] == '':
                    if 'end_offset' in request_info:
                        if request_info['end_offset'] == '':
                            endoffset = 0
                        else:
                            endoffset = request_info['begin_offset']
                        today_start_time = int(today_start_time + endoffset * 3600)

                    self.arg_list.append(key + '=' + str(today_start_time))
                else:
                    if arg_dict[key].isdigit():
                        self.arg_list.append(key + '=' + arg_dict[key])
                    else:
                        endtimeArray = time.strptime(arg_dict[key], "%Y-%m-%d %H:%M:%S")
                        # 指定时间格式 "2018-07-20 16:28:54"
                        self.arg_list.append(key + '=' + str(time.mktime(endtimeArray)))
            else:
                self.arg_list.append(key + '=' + arg_dict[key])
        # 数据范围
        self.range_dict = request_info['range_dict']
import threading
import Codes.Tools.writeLog as writeLog
import Codes.Script.getRootPath as getRootPath
import Codes.Script.getRelPath as getRelPath
import Codes.Tools.mainClass as mainClass
import Codes.Tools.writeTxt as writeTxt
import Codes.Script.sendMail as sendMail
import Codes.Script.globalTime as globalTime
import Codes.Tools.getTime as getTime

globalTime.setGlobalTime(getTime.getTime().getToHour())
rootpath = getRootPath.getRootPath().getPath()
logger = writeLog.writeLogger(loglevel=4, logger="singleThread")
relpath = getRelPath.getRelPath('Codes').getPath() + getRelPath.getRelPath(
    'Config').getPath()
mailconf = rootpath + relpath + 'mailInfo.conf'
threadLock = threading.Lock()


class singleThread(threading.Thread):
    threadID = ''
    name = ''
    logger = ''

    def __init__(self, threadID, name):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name

    def run(self):
        logger.info("开启线程: " + self.name)