示例#1
0
	def get(self,row,params=None,headers=None):
		try:
			r=requests.get(url=self.excel.getUrl(row),
						params=params,
						headers=headers,
						verify=False)
			mylog.info('---%s---,Method:get' %(self.excel.getCaseName(row)))
			return r
		except Exception as e:
			mylog.error('接口%s请求错误,%s'%(self.excel.getCaseName(row),e))
			raise RuntimeError('接口请求发生未知错误')
示例#2
0
	def post(self,row,data=None,headers=None):
		try:
			r=requests.post(
				url=self.excel.getUrl(row),
				data=data,
				headers=headers,
				verify=False)
			mylog.info('---%s---,Method:post' %(self.excel.getCaseName(row)))
			return r
		except Exception as e:
			mylog.error('接口%s请求错误,%s'%(self.excel.getCaseName(row),e))
			print(e)
			raise  RuntimeError('接口请求发生未知的错误')
示例#3
0
 def h5_get(self, row, params=None, headers=None):
     try:
         requests.packages.urllib3.disable_warnings()
         r = requests.get(url=getFixedData(key1='h5url') +
                          self.excel.getUrl(row),
                          params=params,
                          headers=headers,
                          verify=False)
         mylog.info('---%s---,Method:GET' % (self.excel.getCaseName(row)))
         mylog.info('required:%s' % r.request.body)
         return r
     except Exception as e:
         mylog.erro('接口%s请求错误,%s' % (self.excel.getCaseName(row), e))
         raise RuntimeError('接口请求发生未知错误')
示例#4
0
 def web_post(self, row, data=None, headers=None):
     try:
         requests.packages.urllib3.disable_warnings()
         r = requests.post(url=getFixedData(key1='weburl') +
                           self.excel.getUrl(row),
                           data=data,
                           headers=headers,
                           verify=False)
         mylog.info('---%s---,Method:POST' % (self.excel.getCaseName(row)))
         mylog.info('required:%s' % r.request.body)
         return r
     except Exception as e:
         mylog.erro('接口%s请求错误,%s' % (self.excel.getCaseName(row), e))
         print(e)
         raise RuntimeError('接口请求发生未知的错误')
示例#5
0
	def method(self,row,data=None,params=None,headers=None):
		method=self.excel.getMethod(row)
		if method == 'post':
			r=requests.post(
				url=self.excel.getUrl(row),
				data=eval(data),
				headers=headers,
				verify=False)
			mylog.info('---%s---,Method:post' %(self.excel.getCaseName(row)))
			return r
		elif method == 'get':
			r=requests.get(
				url=self.excel.getUrl(row),
				params=eval(params),
				headers=headers,
				verify=False)
			mylog.info('---%s---,Method:get' %(self.excel.getCaseName(row)))
			return r
		else:
			pass
			mylog.error('接口请求方式错误')
示例#6
0
def mail():
    try:
        #创建一个带附件的实例
        message = MIMEMultipart()
        message['From'] = formataddr([username, sender])  #发件人邮箱昵称、发件人邮箱账号
        mylog.info('发件人姓名:%s' % username)
        mylog.info('发件人邮箱:%s' % sender)
        message['To'] = ';'.join(users_email)  #收件人的邮箱,存在多个邮箱用“;”分离
        mylog.info('收件人邮箱:%s' % users_email)
        message['Subject'] = time1 + "支付主流程接口自动化测试报告"  #邮件主题

        #邮件正文内容
        message.attach(MIMEText('附件为支付主流程接口自动化测试报告,请查收!', 'plain', 'utf-8'))

        #添加附件
        att = MIMEText(open(file, 'rb').read(), 'base64', 'utf-8')
        mylog.info('读取附件')
        att['Content-Type'] = 'application/octet-stream'
        # 这里的filename可以任意写,写什么名字,邮件中显示什么名字
        att.add_header("Content-Disposition",
                       "attachment",
                       filename=("gbk", "", "支付主流程接口自动化测试报告.html"))
        # 附件名称非中文时的写法
        # att["Content-Disposition"] = 'attachment; filename="test.html")'
        message.attach(att)
        mylog.info('添加附件')

        server = smtplib.SMTP_SSL("smtp.qq.com", 465)  # 发件人邮箱中的SMTP服务器
        mylog.info('连接QQ邮箱smtp服务')
        server.login(sender, psw)  # 括号中对应的是发件人邮箱账号、邮箱密码
        mylog.info('连接成功')
        server.sendmail(sender, users_email,
                        message.as_string())  # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
        server.quit()  # 关闭连接
        mylog.info("邮件发送成功")

    except Exception as e:
        mylog.error("邮件发送失败,异常信息:%s" % e)