def send_get(self, url, data): result = requests.get(url=url, params=data).json() res = json.dumps(result, ensure_ascii=False, sort_keys=True, indent=2) return res def send_put(self, url, data): result = requests.put(url=url, params=data).json() res = json.dumps(result, ensure_ascii=False, sort_keys=True, indent=2) return res def run_main(self, methond, url=None, data=None): #定义一个run_main函数,通过传过来的methond来进行不同的get和post result = None if methond == 'post': result = self.send_post(url, data) if methond == 'put': result = self.send_put(url, data) elif methond == 'get': result = self.send_get(url, data) else: print("methond值错误!!!!") return result if __name__ == '__main__': requests_url = geturlParams.geturlParams().get_Url('invitation?') result1 = RunMain().run_main('put', url=requests_url, data=None) print(result1)
#coding=utf-8 #author_="bruce.gao" #date:2019/9/27 14:59 import json import unittest from common.configHttp import RunMain import paramunittest from common import geturlParams, readExcel from common.Log import logger logger = logger url = geturlParams.geturlParams().get_Url() taskList_xls = readExcel.readExcel().get_xls('case.xlsx', 'tasklist') @paramunittest.parametrized(*taskList_xls) class testTaskList(unittest.TestCase): """ 任务列表! """ def setParameters(self, case_name, path, query, method, status_code, code, msg, data1, data2): """ set params :param case_name: :param path :param query :param method :return: """
import json import unittest from common.configHttp import RunMain import paramunittest from common import geturlParams import urllib.parse # import pythoncom from testFile.case import readExcel # pythoncom.CoInitialize() url = geturlParams.geturlParams().get_Url() # 调用我们的geturlParams获取我们拼接的URL login_xls = readExcel.readExcel().get_xls('userCase.xlsx', 'login') @paramunittest.parametrized(*login_xls) class testUserLogin(unittest.TestCase): def setParameters(self, case_name, path, query, method): """ set params :param case_name: :param path :param query :param method :return: """ self.case_name = str(case_name) self.path = str(path) self.query = str(query) self.method = str(method)