def __init__(self): # 初始化数据库参数 # 1. 建立连接 # host = "test.lemonban.com" # user = "******" # password = "******" # port = 3306 config = ReadConfig() host = eval(config.get_value("DataBase", "host")) user = eval(config.get_value("DataBase", "user")) password = eval(config.get_value("DataBase", "password")) port = config.get_int("DataBase", "port") self.mysql = pymysql.connect(host=host, user=user, password=password, port=port)
def request(self, method, url, data=None): method = method.upper() # 将字符全部转成大写 config = ReadConfig() path_url = config.get_value('URL', 'path_url') # 拼接 url = path_url + url # URL = ReadConfig(contants.test_api_conf_file).get_value('URL', 'path_url') + url if data is not None and type(data) == str: # data = eval(data) # 如果是字符串就转成字典 data = json.loads(data) # 如果是字符串就转成字典 print('method: {0} url:{1}'.format(method, url)) # 输出确认内容 print('data:{0} '.format(data)) if method == "GET": return self.session.request(method, url=url, params=data) elif method == "POST": return self.session.request(method, url=url, data=data) else: print("Un-support method !!!")
def __init__(self, return_dict=False): # 初始化数据库参数 # host = "test.lemonban.com" # user = "******" # password = "******" # self.mysql = pymysql.connect(host=host, user=user, password=password, port=3306) config = ReadConfig() host = eval(config.get_value("DataBase", "host")) user = eval(config.get_value("DataBase", "user")) password = eval(config.get_value("DataBase", "password")) port = config.get_int("DataBase", "port") # 1. 建立连接 self.mysql = pymysql.connect(host=host, user=user, password=password, port=port) # 2. 新建一个查询页面 if return_dict: self.cursor = self.mysql.cursor( pymysql.cursors.DictCursor) # 指定每行数据以字典形式返回 else: self.cursor = self.mysql.cursor() # 指定每行数据以元祖的形式返回
# coding: utf-8 # python13-api-test # test_api_regitser # shen # 2019/1/21 23:00+ import unittest from common import contants, logger from common.do_excel_study import DoExcel # 导入excel from common.request import Request # 导入api请求 from common.test_api_config import ReadConfig from libext.ddtNew import ddt, data config = ReadConfig() # 正则配置 login_information = eval(config.get_value("Login", "login")) from common.context import Context import json # 一个接口一个类,一个类一个方法 # 一个类,多个方法,多个接接口 # 一个类,一个方法,全部接口 # 导入日志文件 from log.test_api_log import MyLog my_log = MyLog() logger = logger.get_logger(logger_name='LoginTest') # 如果logger_name='case',就是一个单例模式,添加控制台的文本输出样式
# coding: utf-8 # python13-api-test # logger # shen # 2019/2/13 22:39 import logging import logging.handlers from common import contants import os from common.test_api_config import ReadConfig config = ReadConfig() in_level = eval(config.get_value('LogNew', 'in_level')) out_level = eval(config.get_value('LogNew', 'out_level')) file_out_level = eval(config.get_value('LogNew', 'file_out_level')) data_formatter = config.get_value('LogNew', 'fmt') # 输出到文件,文件路径请使用绝对路径 logs # 输出到控制台,定义输出级别debug # 不同的输出级别可配置 def get_logger(logger_name): logger = logging.getLogger(logger_name) logger.setLevel(in_level) # 定义输出格式 # fmt = '[%(asctime)s] - ' # 当前系统时间 # '[%(levelname)s] - ' # 日志信息级别 # '[%(filename)s] - ' # 当前日志所在的文件名、模块名级别
# coding: utf-8 # homework_01.23.19 # test_api_recharge # shen # 2019/1/21 22:07 import unittest from common import contants, logger from common.do_excel_study import DoExcel # 导入excel from common.request import Request # 导入api请求 from common.test_api_config import ReadConfig from libext.ddtNew import ddt, data config = ReadConfig() # # 正则配置 # recharge_information = eval(config.get_value("Recharge", "recharge")) from common.context import Context import json """ 充值,先登录,然后走正常的充值成功流程,接着走异常流程 另一种,调用sessions的方法老师会给代码 """ # 一个接口一个类,一个类一个方法 # 一个类,多个方法,多个接接口 # 一个类,一个方法,全部接口 # 导入日志文件 from log.test_api_log import MyLog
# coding: utf-8 # python13-api-test # test_api_regitser # shen # 2019/1/21 23:00 import unittest from common import contants, logger from common.do_excel_study import DoExcel # 导入excel from common.request import Request # 导入api请求 from common.test_api_config import ReadConfig from libext.ddtNew import ddt, data config = ReadConfig() # 正则配置 bidloan_information = eval(config.get_value("BidLoan", "bidloan")) from common.context import Context import json # 一个接口一个类,一个类一个方法 # 一个类,多个方法,多个接接口 # 一个类,一个方法,全部接口 # 导入日志文件 from log.test_api_log import MyLog my_log = MyLog() logger = logger.get_logger(logger_name='BidLoanTest')
from common import contants from ddt import ddt, data from common.do_excel import DoExcel # 导入excel from common.request import Request # 导入api请求 import json from common.mysql import MysqlUtil # 导入数据库类 import warnings # 导入warning库 忽略 ResourceWarning: unclosed file <_io.TextIOWrapper # 一个接口一个类,一个类一个方法 # 一个类,多个方法,多个接接口 # 一个类,一个方法,全部接口 from common.test_api_config import ReadConfig # 导入配置类 config = ReadConfig() # 正则配置 login_information = eval(config.get_value("Login", "login")) recharge_information = eval(config.get_value("Recharge", "recharge")) withdraw_information = eval(config.get_value("WithDraw", "withdraw")) add_information = eval(config.get_value("Add", "add")) # 还没有添加好正则 bidLoan_information = eval(config.get_value("BidLoan", "bidloan")) """ config 配置参数 recharge_member_phone = config.get_int("RechargeMember", "recharge_member1_phone") recharge_member_id = config.get_int("RechargeMember", "recharge_member1_id") recharge_member_pwd = config.get_int("RechargeMember", "recharge_member_pwd") # login登录配置 withdraw_member_phone = config.get_int("WithDrawMember", "withdraw_member1_phone") withdraw_member_id = config.get_int("WithDrawMember", "withdraw_member1_id") """
# coding: utf-8 # python13-api-test # test_api_regitser # shen # 2019/1/21 23:00 import unittest from common import contants, logger from common.do_excel_study import DoExcel # 导入excel from common.request import Request # 导入api请求 from common.test_api_config import ReadConfig from libext.ddtNew import ddt, data config = ReadConfig() # 正则配置 add_information = eval(config.get_value("Add", "add")) from common.context import Context import json # 一个接口一个类,一个类一个方法 # 一个类,多个方法,多个接接口 # 一个类,一个方法,全部接口 # 导入日志文件 from log.test_api_log import MyLog my_log = MyLog() logger = logger.get_logger(logger_name='AddTest')
# coding: utf-8 # python13-api-test # test_api_regitser # shen # 2019/1/21 23:00 import unittest from common import contants, logger from common.do_excel_study import DoExcel # 导入excel from common.request import Request # 导入api请求 from common.test_api_config import ReadConfig from libext.ddtNew import ddt, data config = ReadConfig() # 正则配置 withdraw_information = eval(config.get_value("WithDraw", "withdraw")) from common.context import Context import json # 一个接口一个类,一个类一个方法 # 一个类,多个方法,多个接接口 # 一个类,一个方法,全部接口 """ """ # 导入日志文件 from log.test_api_log import MyLog my_log = MyLog() logger = logger.get_logger(logger_name='WithDrawTest')
# -*- coding: UTF-8 -*- # python_13 # test_debug # shen # 2019/1/11 20:47 import logging # 导入配置文件 from common import contants from common.test_api_config import ReadConfig config = ReadConfig() in_level = config.get_value('LOG', 'in_level') out_level = config.get_value('LOG', 'out_level') file_level = config.get_value('LOG', 'file_level') file_name = config.get_value('LOG', 'file_name') file_path = eval(config.get_value('LOG', 'file_path')) data_formatter = config.get_value('LOG', 'formatter') import os # current_path = os.getcwd() # report_path = os.path.join(current_path, "Report") class MyLog: '这个是一个日志类' # def __init__(self, in_level, out_level, file_level, file_path, formatter): # 传入配置文件信息 # self.in_level = in_level # self.out_level = out_level