def get_detail(id): """ 根据id获取首页文案 :param id: :return: """ # 拉取title mysql_utils = mysqlUtils.MysqlUtils() title_cmd = "SELECT id, title, subTitle FROM `page` WHERE name=\"" + id + "\";" page_id, title, subTitle = mysql_utils.execute("hospital", title_cmd)[0] # 拉取内容 content_cmd = "SELECT path, sequence, title, subTitle, text FROM `content` WHERE " \ "page_id = \"" + str(page_id) + "\";" content = mysql_utils.execute("hospital", content_cmd) # 按照sequence排序 sorted_content = sorted(content, key=lambda x: x[1]) res_content = [] keys = ["url", "sequence", "title", "subTitle", "text"] # 当前服务host host = readConfig.ReadConfig().read("host", section="service") # 拼接返回内容 for item in sorted_content: dict_item = dict(map(lambda x, y: (x, y), keys, item)) dict_item["url"] = "http://%s/api/resource" % host + dict_item["url"] res_content.append(dict_item) data = { "title": title, "subTitle": subTitle, "id": id, "content": res_content } data = json.dumps(data) return make_response(data)
def test_cm(self): cookie = test_login.login() common_url = conf.ReadConfig().getloginConfigValue('url') jsondatas = ['data'] for i in range(int(get.get_nrows('cm')) - 1): #读取jsonpath jsonpathexcel = get.get_jsonpath('cm', i + 1) # 判断是否执行 if int(get.get_data('cm', i + 1, 4)) == 1: login_url = get.get_data('cm', i + 1, 2) url = common_url + login_url data = get.get_formdata('cm', i + 1, jsondatas[-1]) header = { "Content-Type": "application/x-www-form-urlencoded", "Cookie": cookie } global r print url if get.get_data('cm', i + 1, 3) == 'post': r = requests.post(url=url, headers=header, data=data) time_consume = r.elapsed.microseconds if checkall.checkall('cm', i + 1, r.status_code, r.content) == 'pass': set.set_result(2, i + 1, 'pass') elif checkall.checkall('cm', i + 1, r.status_code, r.content) == 'fail': set.set_result(2, i + 1, 'fail') if jsonpathexcel != '': jsondata = getjson.get_rcontent( json.loads(r.content), jsonpathexcel) jsondatas.append(jsondata) set.set_statuscode(2, i + 1, r.status_code) set.set_content(2, i + 1, r.content.decode('UTF-8')) set.set_sql(2, i + 1, checkdb.check('cm', i + 1)[1]) elif get.get_data('cm', i + 1, 3) == 'get': r = requests.get(url=url, headers=header, data=data) if checkall.checkall('cm', i + 1, r.status_code, r.content) == 'pass': set.set_result(2, i + 1, 'pass') elif checkall.checkall('cm', i + 1, r.status_code, r.content) == 'fail': set.set_result(2, i + 1, 'fail') if jsonpathexcel != '': jsondata = getjson.get_rcontent( json.loads(r.content), jsonpathexcel) jsondatas.append(jsondata) set.set_statuscode(2, i + 1, r.status_code) set.set_content(2, i + 1, r.content.decode('UTF-8')) set.set_sql(2, i + 1, checkdb.check('cm', i + 1)[1]) set.set_time(2, i + 1, str(time_consume)) elif int(get.get_data('cm', i + 1, 4)) == 0: print 'not execute' set.set_result(2, i + 1, 'not execute')
def verify_wx(): """ 微信校验接口(GET) & 用户点击菜单事件推送接口(POST) """ if request.method == 'GET': params = request.args timestamp = params.get('timestamp') nonce = params.get('nonce') token = readConfig.ReadConfig().read('token') signature = params.get('signature') echostr = params.get('echostr') # 开始校验 keys_list = [timestamp, nonce, token] keys_list = sorted(keys_list) raw_str = '' for item in keys_list: try: raw_str += item except TypeError: continue hash_str = hashlib.sha1(raw_str).hexdigest() if signature == hash_str: content = echostr response = make_response(content, status.HTTP_200_OK) else: content = 'Signature error!' response = make_response(content, status.HTTP_406_NOT_ACCEPTABLE) # response, status, headers return response else: response = make_response('Ok') return response
def __init__(self, interval): """ :param interval: 定时器间隔(s) :param env: 环境(online、test) """ self.interval = interval self.redis = edit_redis.EditRedis() self.cf = readConfig.ReadConfig() self.logger = log.Log().get_update_logger()
def get_resource(resource): """ 下载图片 :return: """ # 资源base路径 base_path = readConfig.ReadConfig().read("base_path", section="pictures") path = base_path + "/" + resource image_type = "image/" + resource.split(".")[1] return flask.send_file(path, mimetype=image_type)
def test_pd(self): cookie = test_login.login() common_url = conf.ReadConfig().getloginConfigValue('url') for i in range(int(get.get_nrows('pd')) - 1): # 判断是否执行 if int(get.get_data('pd', i + 1, 4)) == 1: login_url = get.get_data('pd', i + 1, 2) url = common_url + login_url data = get.get_formdata('pd', i + 1) header = { "Content-Type": "application/x-www-form-urlencoded", "Cookie": cookie } global r print url if get.get_data('pd', i + 1, 3) == 'post': r = requests.post(url=url, headers=header, data=data) if checkall.checkall('pd', i + 1, r.status_code, r.content) == 'pass': set.set_result(1, i + 1, 'pass') elif checkall.checkall('pd', i + 1, r.status_code, r.content) == 'fail': set.set_result(1, i + 1, 'fail') set.set_statuscode(1, i + 1, r.status_code) set.set_content(1, i + 1, r.content.decode('UTF-8')) set.set_sql(1, i + 1, checkdb.check('pd', i + 1)[1]) elif get.get_data('pd', i + 1, 3) == 'get': r = requests.get(url=url, headers=header, data=data) if checkall.checkall('pd', i + 1, r.status_code, r.content) == 'pass': set.set_result(1, i + 1, 'pass') elif checkall.checkall('pd', i + 1, r.status_code, r.content) == 'fail': set.set_result(1, i + 1, 'fail') set.set_statuscode(1, i + 1, r.status_code) set.set_content(1, i + 1, r.content.decode('UTF-8')) set.set_sql(1, i + 1, checkdb.check('pd', i + 1)[1]) elif int(get.get_data('pd', i + 1, 4)) == 0: print 'not execute' set.set_result(1, i + 1, 'not execute')
def __init__(self): '''初始化邮件属性''' self.Rc = RC.ReadConfig() self.server = self.Rc.getMail('Smtp_Server') self.sender = self.Rc.getMail('Smtp_Sender') self.password = self.Rc.getMail('Password') self.LReceiver = self.Rc.getMail('OnLine_Receiver') self.PReceiver = self.Rc.getMail('Pre_Receiver') self.TReceiver = self.Rc.getMail('Test_Receiver') self.Msg_Title = self.Rc.getMail('Msg_Title') self.Content_Type = self.Rc.getMail('Content_Type') self.Content_Disposition = self.Rc.getMail('Content_Disposition') self.resultPath = self.Rc.getMail('resultPath') # 实例化MyLog self.log = MyLog.getLog('SendEmail') self.logger = self.log.logger # 实例化msg self.msg = MIMEMultipart()
def login(): common_url = conf.ReadConfig().getloginConfigValue('url') login_url = get.get_data('login', 1, 2) url = common_url + login_url data = json.loads(get.get_data('login', 1, 6)) header = get.get_data('login', 1, 7) global r print url # 判断是否执行 if int(get.get_data('login', 1, 4)) == 1: if get.get_data('login', 1, 3) == 'post': r = requests.post(url=url, data=data, headers=header) if checkall.checkall('login', 1, r.status_code, r.content) == 'pass': set.set_result(0, 1, 'pass') elif checkall.checkall('login', 1, r.status_code, r.content) == 'fail': set.set_result(0, 1, 'fail') elif get.get_data('login', 1, 3) == 'get': r = requests.get(url=url, data=data, headers=header) if checkall.checkall('login', 1, r.status_code, r.content) == 'pass': set.set_result(0, 1, 'pass') elif checkall.checkall('login', 1, r.status_code, r.content) == 'fail': set.set_result(0, 1, 'fail') elif int(get.get_data('login', 1, 4)) == 0: print 'not execute' set.set_result(0, 1, 'not execute') #写status_code和content set.set_statuscode(0, 1, r.status_code) set.set_content(0, 1, r.content) cookie = "WQSESSIONID=" + "".join(r.cookies["WQSESSIONID"]) print cookie return cookie
import json import random import re import time from common import readConfig localReadConfig = readConfig.ReadConfig() #将请求中的时间、随机数参数更换成自定义的参数 def paramfun(param_dict): param_key = param_dict.keys() param_date = { "bussNo": str(int(round(time.time() * 1000))) + ''.join(str(random.choice(range(10))) for _ in range(16)), "bussNo2":time.strftime("%Y%m%d%H%M%S")+''.join(str(random.choice(range(10))) for _ in range(6)), "date": time.strftime("%Y%m%d"), "time": time.strftime("%H%M%S"), "userId1":localReadConfig.get_userid('userId1') } for key in param_key: if param_dict[key] == "$bussNo": param_dict[key] = param_date["bussNo"] elif param_dict[key] == "$bussNo2": param_dict[key] = param_date["bussNo2"] elif param_dict[key] == "$acctNo22": param_dict[key] = list['acctNo'] elif param_dict[key] == "$date": param_dict[key] = param_date["date"]
def get_app_id(): """ 返回appId :return: """ return readConfig.ReadConfig().read("app_id")
import os import win32com.client as win32 import datetime from common import getpathInfo, readConfig from common.Log import logger read_conf = readConfig.ReadConfig() subject = read_conf.get_email('subject') #从配置文件中读取,邮件主题 app = str(read_conf.get_email('app')) #从配置文件中读取,邮件类型 addressee = read_conf.get_email('addressee') #从配置文件中读取,邮件收件人 cc = read_conf.get_email('cc') #从配置文件中读取,邮件抄送人 mail_path = os.path.join(getpathInfo.get_Path(), 'report', 'report.html') #获取测试报告路径 logger = logger class send_email(): def outlook(self): olook = win32.Dispatch("%s.Application" % app) mail = olook.CreateItem(0) mail.To = addressee # 收件人 mail.CC = cc # 抄送 mail.Subject = str( datetime.datetime.now())[0:19] + '%s' % subject #邮件主题 mail.Attachments.Add(mail_path, 1, 1, "myFile") content = """ 执行测试中…… 测试已完成!! 生成报告中…… 报告已生成…… 报告已邮件发送!!
from common import readConfig as readConfig readconfig = readConfig.ReadConfig() class geturlParams(): # 定义一个方法,将从配置文件中读取的进行拼接 def get_Url(self): new_url = readconfig.get_http('scheme') + '://' + readconfig.get_http( 'baseurl') + ':8888' + '/login' + '?' #logger.info('new_url'+new_url) return new_url if __name__ == '__main__': # 验证拼接后的正确性 print(geturlParams().get_Url())
__author__ = 'Administrator' #coding=utf-8 import pymysql, sys import common.readConfig as Reconfig import sys sys.path.insert(1, "..") localReadingConfig = Reconfig.ReadConfig() class MyDB(): def __init__(self, Db): # self.log=Log.get_log() # self.logger=self.log.get_logger() self.db = None self.cursor = None self.Db = Db global host, username, password, port, database, config host = localReadingConfig.get_DB(self.Db, 'host') username = localReadingConfig.get_DB(self.Db, 'username') password = localReadingConfig.get_DB(self.Db, 'password') port = localReadingConfig.get_DB(self.Db, 'port') database = localReadingConfig.get_DB(self.Db, 'database') config = { 'host': str(host), 'user': username, 'password': password, 'port': int(port), 'db': database }
import os import common.HTMLTestRunner as HTMLTestRunner import unittest from common import getpathInfo, readConfig from common.configEmail import send_email import common.Log send_mail = send_email() path = getpathInfo.get_Path() report_path = os.path.join(path, 'report') on_off = readConfig.ReadConfig().get_email('on_off') log = common.Log.logger class AllTest: #定义一个类AllTest def __init__(self): #初始化一些参数和数据 global resultPath resultPath = os.path.join(report_path, "report.html") #report/report.html self.caseListFile = os.path.join(path, "caselist.txt") #配置执行哪些测试文件的配置文件路径 self.caseFile = os.path.join(path, "testCase") #真正的测试断言文件路径 self.caseList = [] log.info('resultPath' + resultPath) #将resultPath的值输入到日志,方便定位查看问题 log.info('caseListFile' + self.caseListFile) #同理 log.info('caseList' + str(self.caseList)) #同理 def set_case_list(self): """ 读取caselist.txt文件中的用例名称,并添加到caselist元素组 :return: