class TestBaseCase(unittest.TestCase): LOGGER = getlog(__name__) @classmethod def setUpClass(cls): # 只执行一次,可以放所有测试执行前的操作 cls.LOGGER.info('开始执行测试用例模块'.center(50, '✈')) @classmethod def tearDownClass(cls): # 只执行一次,可以放所有测试执行后的操作,如:执行sql-delete,重置测试状态 cls.LOGGER.info('测试用例模块执行完毕'.center(50, '✈')) def setUp(self): # 每个测试用例都会执行 self.LOGGER.info('开始执行测试用例'.center(40, '*')) def tearDown(self): # 每个测试用例都会执行 self.LOGGER.info('测试用例执行完成'.center(40, '*'))
""" @Author : QA @File : TbAction.py @desc : 项目:ai 模块:tb 接口方法封装 """ import requests, json, time from common.myCommon import Assertion from common.myConfig import ConfigUtils from common.myCommon.Logger import getlog from common.mydb import MysqlClent from common.myConfig import MysqlConfig TIMEOUT = ConfigUtils.getint('report', 'time_out') baseUrl = MysqlConfig.get('tb_apiURL', 'ai') LOGGER = getlog(__name__) rq = requests.Session() API_TEST_HEADERS = { "Content-Type": "application/json", "Cache-Control": "no-cache" } def test_api_taobao_login(name, password, reqid, token): """ 1、使用用户名密码登录并获取信息 :param password: 密码(必填),string :param reqid: 会话id(非必填),string :param token: 分配的token参数(必填),string :param name: 用户名(必填),string :return: response.text
# -*- coding: utf-8 -*- """ @Time :2019-06-06 下午 4:27 @Author : 罗林 @File : MyPymysqlPool.py @desc : 多线程连接数据库 """ import pymysql from DBUtils.PooledDB import PooledDB from common.myCommon import MyThread from common.myCommon.Logger import getlog from common.myConfig import ConfigUtils as conf LOG = getlog(__name__) QUOTATION = lambda x: '"{}"'.format(x) if isinstance(x, str) else "{}".format(x ) class MyPymysqlPool(object): def __init__(self, dbhost=conf.get('mysql', 'DB_HOST'), dbport=conf.getint('mysql', 'DB_PORT'), dbname=conf.get('mysql', 'DB_NAME'), dbuser=conf.get('mysql', 'DB_USER'), dbpasswd=conf.get('mysql', 'DB_PASSWORD'), charset='utf8', maxconnections=20): """ 数据库构造函数,从连接池中取出连接,并生成操作游标
class SendMail(object): LOG = getlog(__name__) reportPath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + "/testReport/report/" logPath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + "/testReport/log/" if "Windows" in platform.system(): reportPath = reportPath.replace("/", "\\") logPath = logPath.replace("/", "\\") # 邮箱服务器地址 MAIL_HOST = conf.get('mail', 'MAIL_HOST') # 登录邮箱服务器账号 MAIL_USER = conf.get('mail', 'MAIL_USER') # 登录邮箱服务器账号密码 MAIL_PASSWORD = conf.get('mail', 'MAIL_PASSWORD') # 邮箱服务器端口 MAIL_PORT = conf.getint('mail', 'MAIL_PORT') # 收件人邮箱,使用 , 隔开 MAIL_RECEIVER = conf.get('mail', 'MAIL_RECEIVER').split(',') # 抄送人 MAIL_CC_RECEIVER = conf.get('mail', 'MAIL_CC_RECEIVER').split(',') # 邮件标题 MAIL_SUBJECT = conf.get('mail', 'MAIL_SUBJECT') # 邮件类型,普通邮件为 plain ,包含HTML时用html MAIL_TYPE = conf.get('mail', 'MAIL_TYPE') # 邮件附件地址 MAIL_ATTACHMENT = conf.get('mail', 'MAIL_ATTACHMENT').split(',') LOG.info('服务器地址:【{0}】,登录邮箱服务器账号:【{1}】,' '登录邮箱服务器账号密码:【{2}】,' '邮箱服务器端口:【{3}】,收件人邮箱:【{4}】,邮件标题:【{5}】' .format(MAIL_HOST, MAIL_USER, MAIL_PASSWORD, MAIL_PORT, MAIL_RECEIVER, MAIL_SUBJECT)) def sendSMTP(self, sendcontent): """ 发送包普通邮件 :param sendcontent: 正文 """ message = MIMEText(sendcontent, self.MAIL_TYPE, "utf-8") message["From"] = Header(self.MAIL_USER, "utf-8") for toName in self.MAIL_RECEIVER: message["To"] = Header(toName, "utf-8") message["Subject"] = Header(self.MAIL_SUBJECT, "utf-8") self.LOG.info("开始发送邮件".center(40, "*")) try: smtpObj = smtplib.SMTP() smtpObj.connect(self.MAIL_HOST, self.MAIL_PORT) # 25 为 SMTP 端口号 smtpObj.login(self.MAIL_USER, self.MAIL_PASSWORD) smtpObj.sendmail( self.MAIL_USER, self.MAIL_RECEIVER, message.as_string() ) smtpObj.quit() self.LOG.info("邮件发送成功".center(40, "*")) except smtplib.SMTPException: self.LOG.error("Error: 无法发送邮件".center(40, "*")) def sendAttachment(self, sendcontent): """ 发送包含附件的邮件 :param sendcontent: 正文 :return: """ self.LOG.info(u"开始发送邮件".center(40, "*")) # 创建一个带附件的实例 message = MIMEMultipart() message["From"] = Header(self.MAIL_USER, "utf-8") for toName in self.MAIL_RECEIVER: message["To"] = Header(toName, "utf-8") message["Subject"] = Header(self.MAIL_SUBJECT, "utf-8") # 邮件正文内容 message.attach(MIMEText(sendcontent, self.MAIL_TYPE, "utf-8")) for attfile in self.MAIL_ATTACHMENT: # 构造附件1,传送当前目录下的 test.txt 文件 att = MIMEText(open(attfile, "rb").read(), "base64", "utf-8") fileName = open(attfile, "w+").name att["Content-Type"] = "application/octet-stream" # 这里的filename可以任意写,写什么名字,邮件中显示什么名字 att["Content-Disposition"] = "attachment; filename=" + fileName message.attach(att) try: smtpObj = smtplib.SMTP() smtpObj.connect(self.MAIL_HOST, self.MAIL_PORT) # 25 为 SMTP 端口号 smtpObj.login(self.MAIL_USER, self.MAIL_PASSWORD) smtpObj.sendmail( self.MAIL_USER, self.MAIL_RECEIVER, message.as_string() ) smtpObj.quit() self.LOG.info(u"邮件发送成功".center(40, "*")) except smtplib.SMTPException: self.LOG.error(u"Error: 无法发送邮件".center(40, "*")) def __get_report(self): """获取最新测试报告""" self.LOG.info("The report path is : {}".format(self.reportPath)) dirs = os.listdir(self.reportPath) dirs.sort() newreportname = dirs[-1] self.LOG.info("The new report name: {0}".format(newreportname)) return newreportname def __get_logpath(self): """获取最新日志""" self.LOG.info("The log path is : {}".format(self.logPath)) logdirs = os.listdir(self.logPath) logdirs.sort() logname = logdirs[-1] self.LOG.info("The new log path name: {0}".format(logname)) return logname @staticmethod def __read_file(fpath): # 读取文件 BLOCK_SIZE = 1024 with open(fpath, 'rb') as f: while True: block = f.read(BLOCK_SIZE) if block: yield block else: return def send(self): """发送测试结果报告邮件""" self.LOG.info(u"开始发送邮件".center(40, "*")) logname = self.__get_logpath() newreportname = self.__get_report() # 创建一个带附件的实例 message = MIMEMultipart() message["From"] = Header(self.MAIL_USER, "utf-8") for toName in self.MAIL_RECEIVER: message["To"] = Header(toName, "utf-8") """生成邮件的内容,和html报告附件""" message["Subject"] = Header(self.MAIL_SUBJECT, "utf-8") message["date"] = time.strftime("%a, %d %b %Y %H:%M:%S %z") # 读取报告内容,并添加到正文 newreportPath = os.path.join(self.reportPath, newreportname) self.LOG.info(u"添加附件{}".format(newreportPath)) # with open(newreportPath, "rb") as f: # mailbody = f.read() mailbody = '' for item in self.__read_file(newreportPath): mailbody += bytes.decode(item) html = MIMEText(mailbody, _subtype="html", _charset="utf-8") message.attach(html) # html附件 att1 = MIMEText(mailbody, "base64", "gb2312") att1["Content-Type"] = "application/octet-stream" att1["Content-Disposition"] = "attachment; filename={0}".format( newreportname ) # 这里的filename可以任意写,写什么名字,邮件中显示什么名字 message.attach(att1) # log日志附件 newlogPath = os.path.join(self.logPath, logname) self.LOG.info(u"添加附件{}".format(newlogPath)) att2 = MIMEText(open(newlogPath, "rb").read(), "base64", "gb2312") att2["Content-Type"] = "application/octet-stream" att2["Content-Disposition"] = "attachment; filename={0}".format( logname ) # 这里的filename可以任意写,写什么名字,邮件中显示什么名字 message.attach(att2) smtpObj = smtplib.SMTP() try: smtpObj.connect(self.MAIL_HOST, self.MAIL_PORT) # 25 为 SMTP 端口号 smtpObj.login(self.MAIL_USER, self.MAIL_PASSWORD) smtpObj.sendmail( self.MAIL_USER, self.MAIL_RECEIVER, message.as_string() ) self.LOG.info(u"邮件发送成功".center(40, "*")) except smtplib.SMTPException as e: self.LOG.error("Error: 无法发送邮件".center(40, "*")) self.LOG.error("错误原因:{}".format(e)) finally: smtpObj.quit() def send_report(self, project, report_path): """发送测试结果报告邮件""" self.LOG.info(u"开始发送邮件".center(40, "*")) logname = self.__get_logpath() # 创建一个带附件的实例 message = MIMEMultipart() message["From"] = Header(self.MAIL_USER, "utf-8") for toName in self.MAIL_RECEIVER: message["To"] = Header(toName, "utf-8") message["Cc"] = ';'.join(self.MAIL_CC_RECEIVER) """生成邮件的内容,和html报告附件""" subject = project + self.MAIL_SUBJECT + time.strftime("%Y%m%d", time.localtime(time.time())) message["Subject"] = Header(subject, "utf-8") message["date"] = time.strftime("%a, %d %b %Y %H:%M:%S %z") # 读取报告内容,并添加到正文 self.LOG.info(u"添加附件{}".format(report_path)) with open(report_path, "rb") as f: mailbody = f.read() # mailbody = ''.join(FileUtils.readfile(report_path)) # for item in self.__read_file(report_path): # mailbody += bytes.decode(item) html = MIMEText(mailbody, _subtype="html", _charset="utf-8") message.attach(html) # html附件 att1 = MIMEText(mailbody, "base64", "gb2312") att1["Content-Type"] = "application/octet-stream" # 这里的filename可以任意写,写什么名字,邮件中显示什么名字 att1["Content-Disposition"] = "attachment; filename={0}".format(report_path) message.attach(att1) # log日志附件 newlogPath = os.path.join(self.logPath, logname) self.LOG.info(u"添加附件{}".format(newlogPath)) att2 = MIMEText(open(newlogPath, "rb").read(), "base64", "gb2312") att2["Content-Type"] = "application/octet-stream" att2["Content-Disposition"] = "attachment; filename={0}".format( logname ) # 这里的filename可以任意写,写什么名字,邮件中显示什么名字 message.attach(att2) smtpObj = smtplib.SMTP() try: smtpObj.connect(self.MAIL_HOST, self.MAIL_PORT) # 25 为 SMTP 端口号 smtpObj.login(self.MAIL_USER, self.MAIL_PASSWORD) smtpObj.sendmail( self.MAIL_USER, self.MAIL_RECEIVER, message.as_string() ) self.LOG.info(u"邮件发送成功".center(40, "*")) except smtplib.SMTPException as e: self.LOG.error("Error: 无法发送邮件".center(40, "*")) self.LOG.error("错误原因:{}".format(e)) finally: smtpObj.quit()
class MyPyMongo(object): LOG = getlog(__name__) def __init__(self, host, port, mydb, collist, username=None, password=None, use_db=None): """ mongo连接信息 :param host: mongo地址 :param port: 端口 :param username: 用户名 :param password: 密码 :param mydb: 登录默认数据库 :param collist: 使用集合 :param use_db: 使用的数据库 """ self.host = host self.port = port self.username = username self.password = password self.mydb = mydb self.collist = collist self.use_db = use_db m = '连接信息:HOST:【{0}】,PORT:【{1}】,USERNAME:【{2}】,PASSWORD:【{3}】,DB:【{4}】,' \ 'COLLIST集合:【{5}】'.format(self.host, self.port, self.username, self.password, self.mydb, self.collist) try: myclient = MongoClient(self.host, self.port) mydb = myclient[self.mydb] if self.username != '' or self.username is not None: # 连接mydb数据库,账号密码认证 mydb.authenticate(self.username, self.password) self.LOG.debug('SUCCESS client MongoDB : 【{}】'.format(m)) if self.use_db is not None: self.LOG.debug('SUCCESS switch to MongoDB : 【{}】'.format(self.use_db)) mydb = myclient[self.use_db] self.mycol = mydb[self.collist] self.LOG.debug('SUCCESS client collist : 【{}】'.format(self.collist)) except Exception as e: message = 'FAIL client MongoDB : 【{0}】 ,Because : 【{1}】'.format(m, e) self.LOG.error(message) raise e def insert_one(self, mydict): """ 返回插入文档的 id 值 :param mydict: 字典插入值 :return: """ return self.mycol.insert_one(mydict).inserted_id def insert_many(self, mylist): """ 返回插入的所有文档对应的 _id 值 :param mylist: 数组字典插入值 :return: """ return self.mycol.insert_many(mylist).inserted_ids def find_one(self): """ 查询 sites 文档中的第一条数据 :return: """ return self.mycol.find_one() def find(self): """ 查找 sites 集合中的所有数据 :return: """ return [x for x in self.mycol.find()] def find_date(self, myquery): """ 查找 sites 集合中的所有数据 :param myquery: 查询语句 :return: """ myresult = self.mycol.find(myquery) return [x for x in myresult] def find_limit(self, limit, myquery=None): """ 查找 sites 集合中的所有数据 :param limit: 限制条数 :param myquery: 查询语句 :return: """ myresult = self.mycol.find(myquery).limit(limit) return [x for x in myresult] def update_one(self, myquery, newvalues): """ 更新一条数据 :param myquery: 查询语句 :param newvalues: 更新值 :return: """ self.mycol.update_one(myquery, {"$set": newvalues}) def update_many(self, myquery, newvalues): """ 更新多条数据 :param myquery: 查询语句 :param newvalues: 更新值 :return: """ self.mycol.update_many(myquery, {"$set": newvalues}) def find_sort(self, myquery, sort=-1): """ 方法第一个参数为要排序的字段,第二个字段指定排序规则,1 为升序,-1 为降序,默认为升序 :param myquery: 查询语句 :param sort: 排序 :return: """ if sort in (1, -1): mydoc = self.mycol.find().sort(myquery, sort) return [x for x in mydoc] else: raise Exception('please input the sort in 1 or -1') def delete_one(self, myquery): """ 删除一条语句 :param myquery: 查询语句 :return: """ self.mycol.delete_one(myquery) def delete_many(self, myquery=None): """ 删除多条数据 :param myquery: 查询语句 :return: """ if myquery is None: # 传入的是一个空的查询对象,则会删除集合中的所有文档 x = self.mycol.delete_many({}) else: x = self.mycol.delete_many(myquery) self.LOG.debug('{}个文档已删除'.format(x.deleted_count)) def drop(self): """ 删除使用的集合 :return: """ self.mycol.drop()
class Buss4Action(object): LOGGER = getlog(__name__) ############################################################################### # 某模块(点击编辑后双击修改) # # 模块描述: # ############################################################################### def test_getLotteryLists(self, count, start, keyword,): """ 获取热门房地区列表 :return: response.text """ requesturl = baseUrl + "/getLotteryLists" self.LOGGER.info("test_getLotteryLists请求地址:【{}】".format(requesturl)) params = json.dumps({"count": count, "start": start, "keyword": keyword, }) self.LOGGER.info("test_getLotteryLists请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_getHomeConfig(self): """ 获取首页内容(banner数据) :return: response.text """ requesturl = baseUrl + "/getHomeConfig" self.LOGGER.info("test_getHomeConfig请求地址:【{}】".format(requesturl)) params = json.dumps({}) self.LOGGER.info("test_getHomeConfig请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_technews(self, curentpage, pagesize,): """ 开发者资讯 :return: response.text """ requesturl = baseUrl + "/technews" self.LOGGER.info("test_technews请求地址:【{}】".format(requesturl)) params = json.dumps({"curentPage": curentpage, "pageSize": pagesize, }) self.LOGGER.info("test_technews请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_news(self, currentpage, pagesize,): """ 科技动态 :return: response.text """ requesturl = baseUrl + "/news" self.LOGGER.info("test_news请求地址:【{}】".format(requesturl)) params = json.dumps({"currentPage": currentpage, "pageSize": pagesize, }) self.LOGGER.info("test_news请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_topic(self, currentpage, pagesize,): """ 请求热门话题 :return: response.text """ requesturl = baseUrl + "/topic" self.LOGGER.info("test_topic请求地址:【{}】".format(requesturl)) params = json.dumps({"currentPage": currentpage, "pageSize": pagesize, }) self.LOGGER.info("test_topic请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_st_sm_repayment_setting(self, currentpage, pagesize,): """ 支付设置-页面初始化 :return: response.text """ requesturl = baseUrl + "/api/st/sm/repayment/setting" self.LOGGER.info("test_api_st_sm_repayment_setting请求地址:【{}】".format(requesturl)) params = json.dumps({"currentPage": currentpage, "pageSize": pagesize, }) self.LOGGER.info("test_api_st_sm_repayment_setting请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_st_sm_setting_save(self, id, openorclose, remarks,): """ 保存接口 :return: response.text """ requesturl = baseUrl + "/api/st/sm/setting/save" self.LOGGER.info("test_api_st_sm_setting_save请求地址:【{}】".format(requesturl)) params = json.dumps({"id": id, "openOrClose": openorclose, "remarks": remarks, }) self.LOGGER.info("test_api_st_sm_setting_save请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_sm_test(self, id, username, password,): """ 测试接口 :return: response.text """ requesturl = baseUrl + "/sm/test" self.LOGGER.info("test_sm_test请求地址:【{}】".format(requesturl)) params = json.dumps({"id": id, "userName": username, "password": password, }) self.LOGGER.info("test_sm_test请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_periods_applyPeriods(self, amount, period, periodmoney, method,): """ 申请分期 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/periods/applyPeriods" self.LOGGER.info("test_api_78dk_app_periods_applyPeriods请求地址:【{}】".format(requesturl)) params = json.dumps({"amount": amount, "period": period, "periodMoney": periodmoney, "method": method ,"userLocation":''}) self.LOGGER.info("test_api_78dk_app_periods_applyPeriods请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_periods_getConsumption(self, paramsingle,): """ 获取额度测评 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/periods/getConsumption" self.LOGGER.info("test_api_78dk_app_periods_getConsumption请求地址:【{}】".format(requesturl)) params = json.dumps({"paramSingle": paramsingle, }) self.LOGGER.info("test_api_78dk_app_periods_getConsumption请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_periods_getPeriodsOptions(self, money,): """ 获取申请分期 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/periods/getPeriodsOptions" self.LOGGER.info("test_api_78dk_app_periods_getPeriodsOptions请求地址:【{}】".format(requesturl)) params = json.dumps({"money": money, }) self.LOGGER.info("test_api_78dk_app_periods_getPeriodsOptions请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_periods_postUserInfo(self, house, idcard, immediatefamily, job, kinsfolkphone, phone, relationship, username, decorationcityid, decorationdistrictid, decorationinputaddress, decorationprovinceid,): """ 填写基本信息 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/periods/postUserInfo" self.LOGGER.info("test_api_78dk_app_periods_postUserInfo请求地址:【{}】".format(requesturl)) params = json.dumps({"house": house, "idcard": idcard, "immediatefamily": immediatefamily, "job": job, "kinsfolkphone": kinsfolkphone, "phone": phone, "relationship": relationship, "username": username, "decorationCityId": decorationcityid, "decorationDistrictId": decorationdistrictid, "decorationInputAddress": decorationinputaddress, "decorationProvinceId": decorationprovinceid, }) self.LOGGER.info("test_api_78dk_app_periods_postUserInfo请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_periods_certification(self, idcard, phone, username, verifycode,): """ 实名认证 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/periods/certification" self.LOGGER.info("test_api_78dk_app_periods_certification请求地址:【{}】".format(requesturl)) params = json.dumps({"idcard": idcard, "phone": phone, "username": username, "verifycode": verifycode, }) self.LOGGER.info("test_api_78dk_app_periods_certification请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_periods_getVerify(self, mobile,): """ 获取短信验证码 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/base/getVerify" self.LOGGER.info("test_api_78dk_app_periods_getVerify请求地址:【{}】".format(requesturl)) params = json.dumps({"mobile": mobile, }) self.LOGGER.info("test_api_78dk_app_periods_getVerify请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_loan_image_saveContractImages(self): """ 影像资料保存 :param key: {'code': '' :param url: 'data': '' :param : 'msg': ''} :return: response.text """ requesturl = baseUrl + "/api/78dk/app/loan/image/saveContractImages" self.LOGGER.info("test_api_78dk_app_loan_image_saveContractImages请求地址:【{}】".format(requesturl)) params = json.dumps([{"contractImageUuid":"","contractId":"","contractUuid":"","key":"YHSFZZPZM","url":"f12f/215684f12f875fc4982ff938590810acf066cd","originalImageUuid":""},{"contractImageUuid":"","contractId":"","contractUuid":"","key":"YHSFZZPFM","url":"f12f/215684f12f875fc4982ff938590810acf066cd","originalImageUuid":""},{"contractImageUuid":"","contractId":"","contractUuid":"","key":"YHSFZZPSC","url":"32cc/22183732cc17031b1dcd9550f79de5c9ff071f","originalImageUuid":""},{"contractImageUuid":"","contractId":"","contractUuid":"","key":"YHZXHTZP","url":"3e3a/2477093e3ae16110e4592b09b1f7a2c70f609b","originalImageUuid":""},{"contractImageUuid":"","contractId":"","contractUuid":"","key":"YHFCZM","url":"3e3a/2477093e3ae16110e4592b09b1f7a2c70f609b","originalImageUuid":""}]) self.LOGGER.info("test_api_78dk_app_loan_image_saveContractImages请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_loan_image_viewImageRoleList(self, uid,): """ 影像资料权限 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/loan/image/viewImageRoleList" self.LOGGER.info("test_api_78dk_app_loan_image_viewImageRoleList请求地址:【{}】".format(requesturl)) params = json.dumps({"uid": uid, }) self.LOGGER.info("test_api_78dk_app_loan_image_viewImageRoleList请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_loan_image_saveSupplementImage(self, datalists, uid,): """ 影像资料补录保存 :param datalists: {'code': '' :param uid: 'data': '' :param : 'msg': ''} :return: response.text """ requesturl = baseUrl + "/api/78dk/app/loan/image/saveSupplementImage" self.LOGGER.info("test_api_78dk_app_loan_image_saveSupplementImage请求地址:【{}】".format(requesturl)) params = json.dumps({"dataLists": datalists, "uid": uid, }) self.LOGGER.info("test_api_78dk_app_loan_image_saveSupplementImage请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_loan_image_viewImageSupplementList(self, uid,): """ 影像资料补录列表 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/loan/image/viewImageSupplementList" self.LOGGER.info("test_api_78dk_app_loan_image_viewImageSupplementList请求地址:【{}】".format(requesturl)) params = json.dumps({"uid": uid, }) self.LOGGER.info("test_api_78dk_app_loan_image_viewImageSupplementList请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_base_getUserInfo(self, authcode, storeuuid, preferential,): """ 获取用户信息 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/base/getUserInfo" self.LOGGER.info("test_api_78dk_app_base_getUserInfo请求地址:【{}】".format(requesturl)) params = json.dumps({"authCode": authcode, "storeUuid": storeuuid, "preferential": preferential, }) self.LOGGER.info("test_api_78dk_app_base_getUserInfo请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_loan_alipay_getAlipayVid(self): """ 获取支付宝验签Vid :return: response.text """ requesturl = baseUrl + "/api/78dk/app/loan/alipay/getAlipayVid" self.LOGGER.info("test_api_78dk_app_loan_alipay_getAlipayVid请求地址:【{}】".format(requesturl)) params = json.dumps({}) self.LOGGER.info("test_api_78dk_app_loan_alipay_getAlipayVid请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_base_getFddUrl(self): """ 获取法大大合同地址 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/base/getFddUrl" self.LOGGER.info("test_api_78dk_app_base_getFddUrl请求地址:【{}】".format(requesturl)) params = json.dumps({}) self.LOGGER.info("test_api_78dk_app_base_getFddUrl请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_base_getFddResult(self): """ 获取法大大合同签订结果 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/base/getFddResult" self.LOGGER.info("test_api_78dk_app_base_getFddResult请求地址:【{}】".format(requesturl)) # params = json.dumps({"url":url}) params = json.dumps({}) self.LOGGER.info("test_api_78dk_app_base_getFddResult请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_periods_getUserInfo(self): """ 查询基本信息 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/periods/getUserInfo" self.LOGGER.info("test_api_78dk_app_periods_getUserInfo请求地址:【{}】".format(requesturl)) params = json.dumps({}) self.LOGGER.info("test_api_78dk_app_periods_getUserInfo请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_base_getWsAuditResult(self): """ 网商进件 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/base/getWsAuditResult" self.LOGGER.info("test_api_78dk_app_base_getWsAuditResult请求地址:【{}】".format(requesturl)) params = json.dumps({}) self.LOGGER.info("test_api_78dk_app_base_getWsAuditResult请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_user_getUserInfo(self): """ 获取个人信息 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/user/getUserInfo" self.LOGGER.info("test_api_78dk_app_user_getUserInfo请求地址:【{}】".format(requesturl)) params = json.dumps({}) self.LOGGER.info("test_api_78dk_app_user_getUserInfo请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_apply_getRecords(self, pagecurrent, pagesize,): """ 获取申请记录 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/apply/getRecords" self.LOGGER.info("test_api_78dk_app_apply_getRecords请求地址:【{}】".format(requesturl)) params = json.dumps({"pageCurrent": pagecurrent, "pageSize": pagesize, }) self.LOGGER.info("test_api_78dk_app_apply_getRecords请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_apply_getRepaymentPlan(self, pagesize, pagecurrent, paraminfo,): """ 获取还款计划 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/apply/getRepaymentPlan" self.LOGGER.info("test_api_78dk_app_apply_getRepaymentPlan请求地址:【{}】".format(requesturl)) params = json.dumps({"pageSize": pagesize, "pageCurrent": pagecurrent, "paramInfo": paraminfo, }) self.LOGGER.info("test_api_78dk_app_apply_getRepaymentPlan请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_apply_getRecordByUuid(self, paraminfo,): """ 查询单条申请记录 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/apply/getRecordByUuid" self.LOGGER.info("test_api_78dk_app_apply_getRecordByUuid请求地址:【{}】".format(requesturl)) params = json.dumps({"paramInfo": paraminfo, }) self.LOGGER.info("test_api_78dk_app_apply_getRecordByUuid请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_base_getFddCheckUrl(self, uid,): """ 获取法大大合同查看地址 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/base/getFddCheckUrl" self.LOGGER.info("test_api_78dk_app_base_getFddCheckUrl请求地址:【{}】".format(requesturl)) params = json.dumps({"uid": uid, }) self.LOGGER.info("test_api_78dk_app_base_getFddCheckUrl请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_base_list_viewRegionLists(self, paramsingle,): """ 获取区/县下拉列表 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/base/list/viewRegionLists" self.LOGGER.info("test_api_78dk_app_base_list_viewRegionLists请求地址:【{}】".format(requesturl)) params = json.dumps({"paramSingle": paramsingle, }) self.LOGGER.info("test_api_78dk_app_base_list_viewRegionLists请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_base_list_viewCityLists(self, paramsingle,): """ 获取市下拉列表 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/base/list/viewCityLists" self.LOGGER.info("test_api_78dk_app_base_list_viewCityLists请求地址:【{}】".format(requesturl)) params = json.dumps({"paramSingle": paramsingle, }) self.LOGGER.info("test_api_78dk_app_base_list_viewCityLists请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text def test_api_78dk_app_base_list_viewProvinceLists(self): """ 获取省下拉列表 :return: response.text """ requesturl = baseUrl + "/api/78dk/app/base/list/viewProvinceLists" self.LOGGER.info("test_api_78dk_app_base_list_viewProvinceLists请求地址:【{}】".format(requesturl)) params = json.dumps({}) self.LOGGER.info("test_api_78dk_app_base_list_viewProvinceLists请求参数:【{}】".format(params)) response = requests.request( "POST", requesturl, headers=API_TEST_HEADERS, data=params ) self.LOGGER.info("请求结果参数:【{}】".format(response.text)) Assertion.verity(response.status_code, 200, "状态码检查") return response.text
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @Time :2019-05-10 下午 4:58 @Author : 罗林 @File : GlobalDict.py @desc : """ import os from common.myCommon.Logger import getlog from common.myFile import FileUtils log = getlog(__name__) class GlobalDict(object): # 拼装成字典构造全局变量 借鉴map 包含变量的增删改查 def __init__(self, json_file_path, json_file_name): self.file_path = os.path.join(json_file_path, json_file_name + '.json') log.debug("全局变量文件存储位置{}".format(self.file_path)) FileUtils.create_file(self.file_path) self.map = FileUtils.read_json_file(self.file_path) def set(self, **keys): try: for key_, value_ in keys.items(): self.map[key_] = str(value_) log.debug(key_ + ":" + str(value_)) FileUtils.write_json_file(self.file_path, self.map) log.debug("写入键对值{}".format(self.map)) except BaseException as msg: