Ejemplo n.º 1
0
class Method:
	def __init__(self):
		self.operationJson=OperationJson()
		self.excel=OperationExcel()

	def post(self,row,data,**kwargs):
		self.uri = url
		try:
			r=requests.post(
				# 测试环境
				# url="http://192.168.3.15:83" + self.excel.getUrl(row=row),
				#预发环境
				url=self.uri+self.excel.getUrl(row=row),
				data=data,
				headers=getHeadersValue(),
				verify=False,
				timeout=6)
			return r
		except Exception as e:
			raise  RuntimeError('接口请求发生未知的错误')

	def get(self,row,params=None,**kwargs):
		try:
			r=requests.get(
				url="http://192.168.3.15:83"+self.excel.getUrl(row=row),
				params=params,
				# headers=getHeadersValue(),
				timeout=6)
			return r
		except Exception as e:
			raise  RuntimeError('接口请求发生未知的错误')
Ejemplo n.º 2
0
class Method:
    def __init__(self):
        self.operationJson = OperationJson()
        self.excel = OperationExcel()

    def post(self, row, data, header):
        try:
            r = requests.post(url=self.excel.getUrl(row=row),
                              headers=get_headers(header),
                              data=data,
                              timeout=6)
            return r
        except Exception as e:
            raise RuntimeError("接口请求发生未知的错误")

    def get(self, row, params):
        r = requests.get(url=self.excel.getUrl(row=row),
                         params=params,
                         timeout=6)
        return r

    def isContent(self, row, str2):
        flag = None
        if self.excel.getExpect(row=row) in str2:
            flag = True
        else:
            flag = False
        return flag
Ejemplo n.º 3
0
class Method:
    def __init__(self):
        self.operationJson = OperationJson()
        self.excel = OperationExcel()

    def post(self, row, data, **kwargs):
        try:
            r = requests.post(
                url=self.excel.getUrl(row=row),
                data=data,
                # headers=getHeadersValue(),
                timeout=6)
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')

    def get(self, row, params=None, **kwargs):
        try:
            r = requests.get(
                url=self.excel.getUrl(row=row),
                params=params,
                # headers=getHeadersValue(),
                timeout=6)
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')
Ejemplo n.º 4
0
class Method:
	def __init__(self):
		self.operationJson=OperationJson()
		self.excel=OperationExcel()
		self.log=MyLog()

	def post(self,row,data=None):
		try:
			r=requests.post(
				url=self.excel.getUrl(row),
				data=data,
				headers=getHeadersValue(),
				timeout=6)
			self.log.infoLog('接口%s请求成功,请求方式:post,请求参数:%s' %(self.excel.getCaseID(row),data))
			return r
		except Exception as e:
			self.log.errorLog('接口%s请求错误,原因:%s'%(self.excel.getCaseID(row),e))
			raise  RuntimeError('接口请求发生未知的错误')

	def get(self,row,params=None):
		try:
			r=requests.get(url=self.excel.getUrl(row),
						params=params,
						headers=getHeadersValue(),
						timeout=6)
			self.log.infoLog('接口%s请求成功,请求方式:get,请求参数:%s' %(self.excel.getCaseID(row),params))
			return r
		except Exception as e:
			self.log.errorLog('接口%s请求错误,原因:%s'%(self.excel.getCaseID(row),e))
			raise RuntimeError('接口请求发生未知错误')

	def method(self,row,data=None,params=None):
		method=self.excel.getMethod(row)
		if method == 'post':
			r=requests.post(
				url=self.excel.getUrl(row),
				data=data,
				headers=getHeadersInfo(),
				timeout=6)
			self.log.infoLog('接口%s请求成功,请求方式:post,请求参数:%s' %(self.excel.getCaseID(row),data))
			return r
		elif method == 'get':
				r=requests.get(
					url=self.excel.getUrl(row),
					params=params,
					headers=getHeadersInfo(),
					timeout=6)
				self.log.infoLog('接口%s请求成功,请求方式:get,请求参数:%s' %(self.excel.getCaseID(row),params))
				return r
		else:
			self.log.errorLog('接口请求方式不正确')
Ejemplo n.º 5
0
class IsContent:
	def __init__(self):
		self.excel=OperationExcel()

	def isContent(self,row,str2):
		flag=None
		if self.excel.getExpect(row=row) in str2:
			flag=True
		else:
			flag=False
		return flag

		print("https://api.hzxsoft.com"+self.excel.getUrl(row=1))
Ejemplo n.º 6
0
class Method:
    def __init__(self):
        self.operationJson = OperationJson()
        self.excel = OperationExcel()

    def post_yuanshi(self, row):
        '''最原始的post封装'''
        try:
            r = requests.post(
                url=self.excel.getUrl(row=row),
                data=self.operationJson.get_request_data(row=row),
                headers=getHeadersValues(),
                timeout=6)
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')

    def post_update(self, row, data):
        '''请求数据重新修改后,调用的post方法'''
        try:
            r = requests.post(url=self.excel.getUrl(row=row),
                              data=data,
                              headers=getHeadersValues(),
                              timeout=6)
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')

    def put(self, row):
        r = requests.put(url=getUrls(row=row),
                         data=self.operationJson.get_request_data(row=row),
                         headers=getHeadersValues())
        return r

    def delete(self, row):
        r = requests.delete(url=getUrls(row=row), headers=getHeadersValues())
        return r
Ejemplo n.º 7
0
class Method(object):

    def __init__(self):
        self.operationJson = OperationJson()
        self.excel = OperationExcel()

    # def post(self, row):
    #     try:
    #         r = requests.post(
    #             url=self.excel.getUrl(row=row),
    #             data=self.operationJson.getRequestsData(row=row),
    #             headers=checkHeader(row=row,
    #                                 f1=getHeadersValue(),
    #                                 f2=getHeadersInfo()),
    #             timeout=6,
    #             verify=False
    #         )
    #         return r
    #     except Exception as e:
    #         raise RuntimeError('接口请求发生未知的错误')

    def post(self, row, data):
        try:
            r = requests.post(
                url=self.excel.getUrl(row=row),
                data=data,
                headers=getHeadersValue(),
                timeout=6,
                verify=False
            )
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')

    def get(self, url, params=None):
        r = requests.get(url=url, params=params, headers=getHeadersValue(), timeout=6, verify=False)
        return r
Ejemplo n.º 8
0
class Method:

    def __init__(self):
        self.operationJson =OperationJson()
        self.excel = OperationExcel()
        self.excel_pre = OperationExcel_two()
        self.db=database()
        self.header_test = {
            "Host": "10.168.95.149:8022",
            "Content-Type": "application/json;charset=UTF-8",
            "Content-Length": "228",
        }
    def request_wcf(self, url,data):
        # headers = {'Content-Type': 'application/soap+xml; charset="UTF-8"'}
        url_main,url,interface = url.split(",")
        #print(url_main,url,interface)
        client = Client(url_main)
        client.set_options(location = url)#(location = "http://10.168.95.32:5004/FmsAPIServicesForHttpDelegate")
        #print(data_type,type(interface),type(data))
        canshu, data_value = data.split("=", 1) # 把请求数据分成2分,用于判断是对象数据还是一般参数数据
        if data_value[0]!="{":
            "如果接口是正常参数,一个一个赋值"
            request_str = "client.service."+interface+"("+data+")"
            print("请求接口:",request_str)
            result = eval(request_str)
            return str(result)
        else:
            "如果接口参数是对象,则需先创建对象数据"
            data_dict = eval(data_value)
            print(data_dict)
            request_str = "client.service."+interface+"(" + canshu + "=data_dict)"
            print("请求接口:",request_str)
            result = eval(request_str)
            return str(result)
    def get_md5(self,data):
        m = hashlib.md5()
        m.update(data.encode("utf-8"))
        print(m.hexdigest()[8:-8], type(m.hexdigest()[8:-8]))
        return m.hexdigest()[8:-8].upper()

    def get_authorizaiton(self,header_test,account, password):
        author = account + "&" + self.get_md5(account + "&" + password)
        header_test["Authorization"] = "Basic {}".format(author)
        # print(header_test)
        return header_test

    def post(self,row):
        # url = Config().get(self.URL)
        url = self.excel.getUrl(row=row)
        try:
            r = requests.post(
                url=url,
                data=self.operationJson.getRequestsData(row=row),
                headers=getHeadersValue(),
                timeout=6)
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')
    def post_new(self,url,data,header =getHeadersValue() ):
        # url = Config().get(self.URL)
        try:
            r = requests.post(
                url=url,
                data=data,
                headers=header,
                timeout=600)
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')
    def post_with_auth(self,row,account1,password1):
        # url = Config().get(self.URL)
        header_test = {
            "Host": "10.168.95.149:8022",
            "Content-Type": "application/json;charset=UTF-8",
            "Content-Length": "228",
        }
        def get_md5(data):
            m = hashlib.md5()
            m.update(data.encode("utf-8"))
            print(m.hexdigest()[8:-8], type(m.hexdigest()[8:-8]))
            return m.hexdigest()[8:-8].upper()

        def get_authorizaiton(account, password):
            author = account + "&" + get_md5(account + "&" + password)
            header_test["Authorization"] = "Basic {}".format(author)
            #print(header_test)
            return header_test
        url = self.excel.getUrl(row=row)
        try:
            r = requests.post(
                url=url,
                data=self.operationJson.getRequestsData(row=row),
                headers=get_authorizaiton(account1,password1),
                timeout=6,
                )
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')

    def get(self,row):
        url = self.excel.getUrl(row=row)
        try:
            r = requests.get(url=url,
                             timeout=6)
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')
    def get_new(self,row,header):
        url = self.excel.getUrl(row=row)
        try:
            r = requests.get(url=url,headers=header,
                             timeout=6)
            return r
        except Exception as e:
            raise RuntimeError('接口请求发生未知的错误')