Exemplo n.º 1
0
class Context:
    #创建配置文件实例
    config = Reading(http_path.config_path_control)
    #获取数据库最大phone查询sql
    sql = config.get("SQL", "sql_max_Phone")
    #获取配置文件里面项目用户
    normal_uesr = config.get('BASIC', 'normal_uesr')
    # 获取配置文件里面的购买用户
    Income_name = config.get('BASIC', 'Income_name')
    # 获取配置文件里面的pwd
    pwd = config.get('BASIC', 'pwd')
    # 审核用户
    audit_user = config.get('BASIC', 'audit_user')
    # 查询项目用户MemberID
    Member = MysqlUtill().get_fetch_one(config.get("SQL", "sql_PayMemberId"))
    #用户不存在是,ID为空
    if Member is not None:
        PayMemberId = str(Member['Id'])
    else:
        print("反射类里面获取的:PayMemberId为None")
    # 查询购买用户MemberID
    Income = MysqlUtill().get_fetch_one(config.get("SQL",
                                                   "sql_IncomeMemberId"))
    if Income is not None:
        IncomeMemberId = str(Income['Id'])
    else:
        print("反射类里面获取的:PayMemberId为None")
    #查询项目的全部id
    Loan = MysqlUtill().get_fetch_one(config.get("SQL", "sql_LoanId"))
    #还没有新增项目,ID为空
    if Loan is not None:
        LoanId = str(Loan['Id'])
    else:
        print("反射类里面获取的:LoanId为None")
    #最新的项目id
    an = MysqlUtill().get_fetch_one(config.get("SQL", "sql_anId"))
    if an is not None:
        anId = str(an['Id'])
    else:
        print("反射类里面获取的:anId为None")
    # 满标的项目ID
    mark = MysqlUtill().get_fetch_one(config.get("SQL", "Full_mark"))
    if mark is not None:
        Full_mark = str(mark['Id'])
    else:
        print("反射类里面获取的:Full_mark为None")
Exemplo n.º 2
0
 def __init__(self):
     #获取配置文件里面的MySQL配置
     config = Reading(http_path.config_path_control)
     host = config.get('MYSQL', 'Host_name')
     port = config.get_int('MYSQL', 'port')  #port是一个数字,使用getint
     user = config.get('MYSQL', 'user')
     pwd = config.get('MYSQL', 'pwd')
     try:
         self.mysql = pymysql.connect(
             host=host,
             user=user,
             password=pwd,
             database='future',
             port=port,
             cursorclass=pymysql.cursors.DictCursor)
         #cursorclass=pymysql.cursors.DictCursor  返回字典格式
     except BaseException as e:
         print("数据库链接异常:{}".format(e))
         raise e
Exemplo n.º 3
0
# @Software  : PyCharm    
# @User      :skw             
# @Project   :Python12-api-test_9913      
# @Explain   : 日志文件类
"""
from common import http_path
from common.Http_config import Reading
import logging
import time
import os
import HTMLTestRunnerNew
from logging.handlers import TimedRotatingFileHandler  #根据时间进行滚动
from logging.handlers import RotatingFileHandler  #根据文件大小进行滚动

my_log = logging.getLogger(
    Reading(http_path.config_path_control).get('LOG', 'logger_name'))
my_log.setLevel(Reading(http_path.config_path_control).get('LOG', 'log_level'))
leve = Reading(http_path.config_path_control)
fmt = " %(asctime)s  %(levelname)s %(filename)s %(funcName)s [ line:%(lineno)d ] %(message)s"
#%%(asctime)s-%%(levelname)s-%%(filename)s-%%(funcName)-s[line:%%(lineno)d]-%%(name)s
fmt1 = leve.get('LOG', 'formatter')
datefmt = '%a, %d %b %Y %H:%M:%S'
Console = logging.StreamHandler()
#格式Fri, 03 Aug 2018 17:02:05 周几+日期+月份+年份+时+分+秒
curTime = time.strftime('%Y-%m-%d', time.localtime(time.time()))


def get_log_dir():  # 获取当天的日志存放目录
    log = os.path.join(http_path.log_path, curTime)  #基本路径+当天时间
    if not os.path.isdir(log):  #判断是否有当天时间的日志目录
        os.makedirs(log)  #没有新建一个目录
Exemplo n.º 4
0
class HttpLog:
    info_file = os.path.join(get_log_dir(), 'info.log')  #最终日志路径
    error_file = os.path.join(get_log_dir(), 'error.log')
    #日志输出格式
    farmatter = logging.Formatter(
        Reading(http_path.config_path_control).get('LOG', 'formatter'))
    #创建渠道,设置级别,输出格式, 控制台输出
    handler = logging.StreamHandler()
    handler.setLevel(
        Reading(http_path.config_path_control).get('LOG', 'handler_level'))
    handler.setFormatter(farmatter)
    # 创建本地INFO级别的日志文件,输出格式
    # 写入文件,如果文件超过5M,仅保留5个文件。
    file_handler = logging.handlers.RotatingFileHandler(filename=info_file,
                                                        maxBytes=1024 * 1024 *
                                                        5,
                                                        backupCount=5,
                                                        encoding='utf-8',
                                                        delay=False)
    file_handler.suffix = "%Y-%m-%d_%H-%M.log"
    file_handler.setLevel(
        Reading(http_path.config_path_control).get('LOG', 'info_level'))
    file_handler.setFormatter(farmatter)
    # 创建本地ERROR级别的日志文件,输出格式
    # 添加TimedRotatingFileHandler
    # 定义一个1天换一次log文件的handler
    # 保留3个旧log文件
    error_handler = logging.handlers.TimedRotatingFileHandler(
        filename=error_file,
        when='D',
        interval=1,
        backupCount=3,
        encoding='utf-8')
    error_handler.suffix = "%Y-%m-%d_%H-%M.log"
    error_handler.setLevel(
        Reading(http_path.config_path_control).get('LOG', 'error_level'))
    error_handler.setFormatter(farmatter)
    # 报表日志输出,在控制台展示
    report_handler = logging.StreamHandler(HTMLTestRunnerNew.stdout_redirector)
    report_handler.setLevel(
        Reading(http_path.config_path_control).get('LOG', 'report_level'))
    report_handler.setFormatter(farmatter)

    #创建日志级别函数
    @staticmethod
    def debug(msg):
        set_handler('DEBUG')
        my_log.debug(msg)
        remove_handler('DEBUG')

    @staticmethod
    def info(msg):
        set_handler('INFO')
        my_log.info(msg)
        remove_handler('INFO')

    @staticmethod
    def error(msg):
        set_handler('ERROR')
        my_log.error(msg, exc_info=True)  # 同时输出异常信息
        remove_handler('ERROR')
Exemplo n.º 5
0
# @Email    : [email protected]
# @File     : http_log.py
# @Software : PyCharm
# @Explain  : 日志文件

from common import http_path
from common.Http_config import Reading
import logging
import time
import os
import HTMLTestRunnerNew
from logging.handlers import TimedRotatingFileHandler  #根据时间进行滚动
from logging.handlers import RotatingFileHandler  #根据文件大小进行滚动
# 创建日志,并设置级别
my_log = logging.getLogger(
    Reading(http_path.config_path_control).get('LOG', 'logger_name'))
my_log.setLevel(Reading(http_path.config_path_control).get('LOG', 'log_level'))


def set_handler(level):  # 对接渠道和文件
    if level == 'ERROR':  #判断级别是否是ERROR,是,就对接error_handler
        my_log.addHandler(HttpLog.error_handler)
    else:
        my_log.addHandler(HttpLog.file_handler)  #否,对接file_handler
    my_log.addHandler(HttpLog.handler)  # 那个级别的日志,在控制台console中显示
    #my_log.addHandler(HttpLog.report_handler)       # 全部输出到report


def remove_handler(level):  #移除链接
    if level == 'ERROR':
        my_log.removeHandler(HttpLog.error_handler)
Exemplo n.º 6
0
from ddt import ddt,data,unpack
from common.http_requests_01 import HttpRequest
from common.http_reading_excel_01 import DoExcel
from common import http_path
from common.Http_config import Reading
from common.http_log import HttpLog
from common.regular_expression import Regular
from common.basic_data import Context
from common.mysql import MysqlUtill
import unittest
import json
from common.common_user import Login
#创建日志对象,装载日志
my_log = HttpLog()
#创建取配置对象
con = Reading(http_path.config_path_control)
#获取需要的执行的测试用例ID
config = con.get('CASE','button')
#读取配置文件里面的URL地址
config_url = con.get('URL','url_date')
#读取测试数据,实例化测试数据对象
excel_date = DoExcel(http_path.case_path,config)
#充值
excel_date_recharge = excel_date.get_case('recharge2')

@ddt
class HttpCase(Login):
#class HttpCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        Login().test_login()    #固定投资用户登录