Ejemplo n.º 1
0
 def check_res(self, res, check):
     # res = res.replace('": "', '=').replace('": ', '=')  # 两次替换,把res里返回的字典里所有的替成=号(因为返回的Json串格式都是一样的)
     print("-----------", res)
     for c in check.split(','):  # 将预期结果里的以逗号分开
         if c not in res:  # 判断预期结果里的list是否在返回结果res里
             atp_log.info('结果校验失败,预期结果:【%s】,实际结果【%s】' % (c, res))
             return '失败'
     return '成功'
 def check_res(self, res, check):
     # 将响应数据中的  ": "  替换成  =
     res = res.replace('": "', '=').replace('": ', '=')
     for c in check.split(','):  # 预期结果按照逗号拆分,并遍历,判断拆分之后的请求响应数据是否包含预期结果
         if c not in res:
             atp_log.info('结果校验失败,预期结果:【%s】,实际结果【%s】' % (c, res))
             return '失败'
     return '成功'
Ejemplo n.º 3
0
def sendmail(title, content, attrs=None):
    # 以下邮箱的配置直接写在setting中,方便管理修改
    m = yagmail.SMTP(
        host=setting.MAIL_HOST,
        user=setting.MAIL_USER,
        password=setting.MAIL_PASSWRD,  # 邮箱的授权码
        smtp_ssl=True)  # QQ邮箱时需要添加smtp_ssl=True
    m.send(to=setting.TO, subject=title, contents=content, attachments=attrs)
    atp_log.info('发送邮件完成')
Ejemplo n.º 4
0
 def check_res(self, res, check):  #res:实际结果,check:预期结果
     res = res.replace('": "', '=').replace('": ',
                                            '=')  #这句表示是否完全匹配(注释后需要全完匹配)
     #print('res',res)#实际返回结果
     for c in check.split(','):
         print('cccc', c)
         if c not in res:
             atp_log.info('结果校验失败,预期结果:【%s】,实际结果【%s】' % (c, res))
             return '失败'
         return '成功'
Ejemplo n.º 5
0
def sendmail(title,content,attrs=None):
    m = yagmail.SMTP(host=setting.MAIL_HOST,user=setting.MAIL_USER,
                 password=setting.MAIL_PASSWRD,smtp_ssl=False)

    m.send(to=setting.TO,
           subject=title,
           contents = content,
           attachments =attrs)

    atp_log.info('发送邮件完成')
def sendmail(title,content,attrs=None):
	m = yagmail.SMTP(host=setting.MAIL_HOST,# 邮件HOST地址
					 user=setting.MAIL_USER # 用户名
				 	,password=setting.MAIL_PASSWRD # 授权码
				 	)
	m.send(to=setting.TO,# 接收用户,可以多个
		   subject=title,# 邮件主题
		   contents=content, # 邮件内容
		   attachments=attrs # 附件,多个附件则传入一个['1.txt','2.txt']
		   )
	atp_log.info('发送邮件完成') # 记录日志,打印log
Ejemplo n.º 7
0
def gettoken():
    filepath = r'C:\\Users\\cherrylixh\\PycharmProjects\\ATP\\conf\\2.yaml'
    f = open(filepath)
    res = yaml.load(f)
    req = res[0]
    host = req['host']
    url = req['url']
    data = req['data']
    try:
        rew = requests.get(host + url, params=data)
        token = rew.json()['result']['token']
        atp_log.info('gettoken:%s' % token)
        return token
    except Exception as e:
        atp_log.error('获取token失败')
Ejemplo n.º 8
0
 def get_case(self, file_path):
     cases = []  #定义一个列表存放所有的cases
     if file_path.endswith('.xls') or file_path.endswith('.xlsx'):
         try:
             book = xlrd.open_workbook(file_path)
             sheet = book.sheet_by_index(0)
             for i in range(1, sheet.nrows):
                 row_data = sheet.row_values(i)  #获取的每一行数据存到列表row_data
                 cases.append(row_data[4:9])  #追加到cases空列表
             atp_log.info('共读取%s条用例' % (len(cases)))
             self.file_path = file_path  #因为该函数已经传了参数路径,为方便write_excel引用,在此实例化
         except Exception as e:
             atp_log.error('[%s]用例获取失败,错误信息:%s' % (file_path, e))
     else:
         atp_log.error('用例文件不合法,%s' % file_path)
     return cases
 def get_case(self, file_path):
     cases = []  # 存放所有的case
     if file_path.endswith('.xls') or file_path.endswith('.xlsx'):
         try:
             book = xlrd.open_workbook(file_path)  # 读取指定excel,获取book对象
             sheet = book.sheet_by_index(0)  # 获取第一页
             # 循环所有行,提取 4<= 列下标 <8 之间的列的数据
             for i in range(1, sheet.nrows):
                 row_data = sheet.row_values(i)  # 获取当前行的所有数据
                 cases.append(row_data[4:8])  # 截取指定部分的数据存入到列表
             atp_log.info('共读取%s条用例' % (len(cases)))
             self.file_path = file_path  # 绑定文件地址到对象file_path属性上
         except Exception as e:
             atp_log.error('【%s】用例获取失败,错误信息:%s' % (file_path, e))
     else:
         atp_log.error('用例文件不合法的,%s' % file_path)
     return cases
Ejemplo n.º 10
0
 def get_case(self, file_path):
     cases = []  # 存放所有的case
     if file_path.endswith('.xls') or file_path.endswith(
             '.xlsx'):  # 判断文件是否为excel文件
         try:  #
             book = xlrd.open_workbook(file_path)  # 打开excel
             sheet = book.sheet_by_index(0)  # 获取sheet页
             for i in range(1, sheet.nrows):  # 循环每一行
                 row_data = sheet.row_values(i)  # 获取每一行数据
                 cases.append(row_data[3:7])  # 将第5-8列的数据添加到case中
             atp_log.info('共读取%s条用例' % (len(cases)))  # 一共有多少条测试用例
             self.file_path = file_path  # 实例化file_path
         except Exception as e:
             atp_log.error('【%s】用例获取失败,错误信息:%s' % (file_path, e))
     else:  # 如果文件不是excel,提示
         atp_log.error('用例文件不合法的,%s' % file_path)
     return cases  # 返回case
Ejemplo n.º 11
0
 def get_cases(self, filepath):
     cases = []  #保存用例
     print('filepath%s' % filepath)
     if filepath.endswith('.xls') or filepath.endswith('xlsx'):
         try:
             book = xlrd.open_workbook(filepath)  #打开文件
             sheet = book.sheet_by_index(0)  #获取第一个sheet表
             nrows = sheet.nrows  #获取表格行数
             for i in range(1, nrows):  #从第2行循环读取用例
                 row_data = sheet.row_values(i)  #获取每行的数据,返回一个list
                 cases.append(
                     row_data[4:9])  #获取4-9列的数据放入cases:url,methos,data,check
             atp_log.info('共有%s条用例' % len(cases))
             self.filepath = filepath
             print('cases:%s' % cases)
         except Exception as e:
             atp_log.error('文件打开失败:%s' % e)
     else:
         atp_log.error('用例格式不合法,需要xls或xksx:%s' % filepath)
     return cases
Ejemplo n.º 12
0
 def requestTest(self, *args, **kwargs):
     detail = kwargs.get('detail', 'no detail')
     self._testMethodDoc = detail
     host = kwargs.get('host')
     url = kwargs.get('url')
     url = parse.urljoin(host, url)
     method = kwargs.get('method', 'get')
     data = kwargs.get('data', {})
     header = kwargs.get('header', {})
     cookie = kwargs.get('Cookie'.lower(), {})
     #args是data中需要传入的参数key值,由于kwargs中已经更新了手动加入的参数,现在需要把这个参数放在data字典中,cookie是单独放在header中不能放在body中
     if (len(args) > 0):
         for c in args:
             atp_log.info('c:%s' % c)
             if c.lower() == 'cookie':
                 continue
             #将需要手动传入的数据放在data,key值是传入时的args,value值放在已更新的kwargs对应的key中
             data[c] = kwargs[c]
     atp_log.info('data:%s' % data)
     check = kwargs.get('check')
     method = method.lower()
     try:
         #根据method判断需要执行哪个命令
         if method == 'get':
             res = requests.get(url,
                                params=data,
                                cookies=cookie,
                                headers=header)
         else:
             res = requests.post(url, data, cookies=cookie, headers=header)
         req = res.text
         atp_log.info('responde:%s' % req)
         return res
     except Exception as e:
         atp_log.error('requestTest: %s' % e)
         print('请求接口出错')
         req = e
         #断言,yaml中checklist是否包含在返回的结果中
     for c in check:
         self.assertIn(c, req, msg='预期结果不符,预期结果%s,实际结果%s' % (c, req))
Ejemplo n.º 13
0
 def testlogin(self, *args, **kwargs):
     res = BaseTest().requestTest(*args, **kwargs)
     print('testlogin_res:%s' % res.json())
     atp_log.info('testlogin:%s' % res.json())