Ejemplo n.º 1
0
def get_logger(name):
    logger = logging.getLogger(name)
    logger.setLevel('DEBUG')
    formatter = logging.Formatter(
        "%(asctime)s-%(name)s-%(levelname)s-日志信息:%(message)s-[%(filename)s:%(lineno)d]"
    )

    #设置输出到控制台
    console_handler = logging.StreamHandler()
    console_level = config.get('logger', 'console_level')
    console_handler.setLevel(console_level)
    console_handler.setFormatter(formatter)

    #设置输出到配置文件
    file_handler = logging.FileHandler(file_adress.log_dir + '/cases.log',
                                       encoding='utf-8')
    file_level = config.get('logger', 'file_level')
    file_handler.setLevel(file_level)
    file_handler.setFormatter(formatter)
    #关联
    logger.addHandler(console_handler)
    logger.addHandler(file_handler)

    #关闭输出
    logger.removeHandler(console_handler)
    logger.removeHandler(file_handler)
    return logger
Ejemplo n.º 2
0
    def loadingDataConfig(self, Host, excel_name, Sheet_name):
        # 从配置文件中读取文件名,表单名,列数
        file_name = config.get('excel', 'excel_name')

        file_path = os.path.join(data_path, file_name)
        sheet_name = config.get('excel', 'Sheet_name')
        columns = config.get('excel', 'columns')
        self.rootUrl = config.get('Host', Host)  # 获取host配置的请求跟路径
        self.rooUrlEndWithSlash = self.rootUrl.endswith('/')
        self.params = dict(config.items('params'))  # 读取param,并将值保存到公共数据
        self.setSaveDates(self.params)
        self.publicHeaders = dict(
            config.items('headers'))  # headers,并将值保存到publicHeaders,
Ejemplo n.º 3
0
 def get_cases(self):
     mode = eval(config.get("CASE_MODE", "mode"))
     test_data = []
     for key in mode:
         self.sheet = self.wb[key]
         if mode[key] == 'all':
             for i in range(2, self.sheet.max_row + 1):
                 case = Case()
                 case.case_id = self.sheet.cell(row=i, column=1).value
                 case.title = self.sheet.cell(row=i, column=2).value
                 case.method = self.sheet.cell(row=i, column=3).value
                 case.url = self.sheet.cell(row=i, column=4).value
                 case.data = self.sheet.cell(row=i, column=5).value
                 case.expected = self.sheet.cell(row=i, column=6).value
                 case.sql = self.sheet.cell(row=i, column=9).value
                 case.sheet_name = key
                 test_data.append(case)
         else:
             for case_id in mode[key]:
                 case = Case()
                 case.case_id = self.sheet.cell(row=case_id + 1,
                                                column=1).value
                 case.title = self.sheet.cell(row=case_id + 1,
                                              column=2).value
                 case.method = self.sheet.cell(row=case_id + 1,
                                               column=3).value
                 case.url = self.sheet.cell(row=case_id + 1, column=4).value
                 case.data = self.sheet.cell(row=case_id + 1,
                                             column=5).value
                 case.expected = self.sheet.cell(row=case_id + 1,
                                                 column=6).value
                 case.sql = self.sheet.cell(row=case_id + 1, column=9).value
                 case.sheet_name = key
                 test_data.append(case)
Ejemplo n.º 4
0
 def __init__(self):
     self.params = dict(config.items('params'))  # 读取param,并将值保存到公共数据
     self.setSaveDates(self.params)
     self.publicHeaders = dict(
         config.items('headers'))  # headers,并将值保存到publicHeaders,
     self.rootUrl = config.get('Host', 'rootUrl')  # 获取host配置的请求跟路径
     self.rooUrlEndWithSlash = self.rootUrl.endswith('/')
Ejemplo n.º 5
0
def send_email(report_file):
    msg = MIMEMultipart()  # 混合MIME格式
    # 添加html格式邮件正文(会丢失css格式)
    msg.attach(
        MIMEText(open(report_file, encoding='utf-8').read(), 'html', 'utf-8'))
    now_time = time.strftime('%Y-%m-%d_%H_%M_%S')  #获取时间戳
    msg['From'] = '*****@*****.**'  # 发件人
    msg['To'] = '*****@*****.**'  # 收件人
    msg['Subject'] = Header(now_time + config.get('EMAIL', 'subject'),
                            'utf-8')  # 中文邮件主题,指定utf-8编码

    att1 = MIMEText(open(report_file, 'rb').read(), 'base64',
                    'utf-8')  # 二进制格式打开
    att1["Content-Type"] = 'application/octet-stream'
    att1[
        "Content-Disposition"] = 'attachment;filename="test_report.html"'  # filename为邮件中附件显示的名字
    msg.attach(att1)

    try:
        smtp = smtplib.SMTP_SSL('smtp.163.com')
        smtp.login('*****@*****.**', "FSRTHIDKXBWEUZNC")  # 从配置文件中读取
        smtp.sendmail('*****@*****.**', '*****@*****.**',
                      msg.as_string())
        logger.info("邮件发送完成!")
        smtp.quit()
    except Exception as e:
        logger.error(str(e))
Ejemplo n.º 6
0
 def request(self, method, url, data=None, json=None):
     if type(data) == str:
         data = eval(data)
     #拼接请求的url
     url = config.get('URL', 'web_url') + url
     logger.debug("请求的url{}".format(url))
     logger.debug("请求的data{}".format(data))
     try:
         if method.lower() == 'get':
             res = self.session.request(method=method, url=url, params=data)
         elif method.lower() == 'post':
             if json:
                 res = self.session.request(method=method,
                                            url=url,
                                            json=json)
             else:
                 res = self.session.request(method=method,
                                            url=url,
                                            data=data)
         else:
             res = None
             logger.error("不支持的请求方法")
     except Exception as e:
         logger.error("请求报错了{}".format(e))
         raise e
     return res
Ejemplo n.º 7
0
 def test_1(self, api):
     try:
         url = config.get('auditcenter', 'url') + api
         response = request(method='get', url=url)
         self.assertEqual(response.json()['code'], '200')
         self.assertEqual(response.json()['message'], 'OK')
     except AssertionError:
         print('断言失败')
         raise
Ejemplo n.º 8
0
    def readExcelData(self):

        # 从配置文件中读取文件名,表单名,列数
        file_name = config.get('excel', 'excel_name')

        file_path = os.path.join(data_path, file_name)
        sheet_name = config.get('excel', 'Sheet_name')
        columns = config.get('excel', 'columns')
        self.rootUrl = config.get('Host', 'rootUrl')  # 获取host配置的请求跟路径
        self.rooUrlEndWithSlash = self.rootUrl.endswith('/')
        self.params = dict(config.items('params'))  # 读取param,并将值保存到公共数据
        self.setSaveDates(self.params)
        self.publicHeaders = dict(
            config.items('headers'))  # headers,并将值保存到publicHeaders,

        # 读取表格数据
        r = ReadExcel(file_path, sheet_name)
        cases = r.r_data_obj(columns)
        return cases
Ejemplo n.º 9
0
 def setUpClass(cls):
     cls.base_url = config.get('auditcenter', 'url') + '/api/v1/exportList'
Ejemplo n.º 10
0
 def setUpClass(cls):
     cls.base_url = config.get('auditcenter',
                               'url') + '/api/v1/deptForReport'
Ejemplo n.º 11
0
 def __init__(self):
     self.session = requests.session()
     self.uername = config.get('default','username')
     password = str(config.get('default', 'password'))
     self.password = self.handle_password(password)
Ejemplo n.º 12
0
 def start_sf(self):
     url = config.get('auditcenter','url') + '/api/v1/startAuditWork'
     response = self.session.get(url)
Ejemplo n.º 13
0
 def setUpClass(cls):
     cls.base_url = config.get('default','address') + '/knowledge/api/v1/dictionaryDataTree'
Ejemplo n.º 14
0
# @Software: PyCharm
import json
import re
import unittest
import os

from common.constant import data_path
from common.do_excel import ReadExcel
from common.logger import log
from common.read_config import config
from common.test_base import TestBase, StringUtil, AssertUtil

from librarys.ddt import ddt, data

# 从配置文件中读取文件名,表单名,列数
file_name = config.get('excel', 'excel_name')

file_path = os.path.join(data_path, file_name)
sheet_name = config.get('excel', 'Sheet_name')
columns = config.get('excel', 'columns')

# 读取表格数据
r = ReadExcel(file_path, sheet_name)
testBase = TestBase()
cases = testBase.filterData(r.read_data_obj())


# 创建测试类
@ddt
class RegisterTestcase(unittest.TestCase, TestBase):
    # 重写父类__init__方法
Ejemplo n.º 15
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2019/6/17 11:52
# @Author  : Jandy
# @Email   : [email protected]
# @File    :run.py
# @Software: PyCharm
import unittest
import os

from common.read_config import config
from librarys.HTMLTestRunnerNew import HTMLTestRunner
from common.constant import testcase_path
from common.constant import report_path

# from HTMLTestRunnerNew import HTMLTestRunner
#获取报告文件名
report_name = config.get('report', 'report_name')
#创建测试集合
suite = unittest.TestSuite()
#创建加载套件
loader = unittest.TestLoader()
suite.addTest(loader.discover(testcase_path))

with open(os.path.join(report_path, report_name), 'wb+') as f:
    runner = HTMLTestRunner(stream=f,
                            verbosity=2,
                            title='接口测试',
                            description='api测试',
                            tester='jandy')
    runner.run(suite)
Ejemplo n.º 16
0
        my_log.addHandler(l_s)
        my_log.addHandler(l_f)

        #设置日志输出格式
        ft = '%(asctime)s - [%(filename)s-->line:%(lineno)d] - %(levelname)s: %(message)s'
        # ft = '%(asctime)s-%(levelname)s-%(filename)s-%(name)s-日志信息:%(message)s'
        ft = logging.Formatter(ft)
        l_s.setFormatter(ft)
        l_f.setFormatter(ft)

        #返回日志收集器
        return my_log


# 获取配置文件中日志收集器的名字
log_name = config.get('log', 'logger_name')
# 获取配置文件中的日志级别
log_level = config.get('log', 'level').upper()
#日志文件名
file_name = config.get('log', 'log_name')
#日志文件路径
file_path = os.path.join(log_path, str(time.strftime('%Y-%m-%d')) + file_name)

#创建日志收集器
log = MyLogging().create_mylog(log_name, log_level, file_path)
#输出日志
log.debug('debug级别')
log.info('info级别')
log.warning('warning级别')
log.error('error级别')
log.critical('critical日志级别')
Ejemplo n.º 17
0
 def setUpClass(cls):
     log.info('------开始执行{}测试用例------'.format(cls.__doc__))
     cls.g = globals()
     cls.base_url = config.get('auditcenter', 'url') + '/api/v1/auditPlan'
     cls.plan_list = config.get('auditcenter', 'url') + '/api/v1/auditPlanList'
     cls.plan_name = "测试审方方案"
Ejemplo n.º 18
0
        return cases

    def write(self, row, column, msg):
        '''

        :param row: 行 -->int
        :param column: 列-->int
        :param msg:   写入数据
        :return:
        '''
        self.sh.cell(row=row, column=column, value=msg)
        self.wb.save(self.filename)


# 文件名 ,表单名
file_name = config.get('excel', 'excel_name')
file_path = os.path.join(data_path, file_name)
sheet_name = config.get('excel', 'sheet_name')
# file_path = 'E:/PycharmProjects/auto_test/test_data/api-data.xlsx'
# sheet_name = 'Sheet2'
if __name__ == '__main__':
    read = ReadExcel(file_path, sheet_name)
    resul = read.read_data_obj()
    # resul = read.r_data_obj()

    for x in resul:
        print(x.__dict__)
        # print(TestBase().buildParam(x.__dict__['param']))
#
# if __name__ == '__main__':
#     test_da = DoExcel('E:/PycharmProjects/auto_test/test_data/api-data.xlsx', 'data-test').read_excel()
Ejemplo n.º 19
0
 def login(self):
     url = config.get('default','address') + '/syscenter/api/v1/currentUser'
     data = {"name": self.uername, "password": self.password}
     headers = {'Content-Type': "application/json"}
     response = self.session.post(url,data=json.dumps(data),headers=headers)