Exemplo n.º 1
0
    def request(self):

        if self.method.upper() == 'GET':
            '''
                   发送get 请求
                   :return: 响应对象
                   '''
            try:
                response = requests.get(url=self.url,
                                        params=self.params,
                                        headers=self.headers,
                                        timeout=float(self.timeout))
                return response
            except TimeoutError:
                MyLog.get_log().error("timeout")
                pass
        elif self.method.upper() == 'POST':
            '''
                    发送post请求
                    :return:
                    '''
            try:
                response = requests.post(self.url,
                                         data=self.data,
                                         headers=self.headers,
                                         timeout=float(self.timeout))
                return response
            except TimeoutError:
                MyLog.get_log().error("timeout")
                pass

        elif self.method.upper() == 'POSTWITHJSON':
            try:
                response = requests.post(self.url,
                                         headers=self.headers,
                                         json=self.data,
                                         timeout=float(self.timeout))
                return response
            except TimeoutError:
                MyLog.get_log().error("Time out!")
                pass
        elif self.method.upper() == 'POSTWITHFILE':
            try:
                response = requests.post(self.url,
                                         headers=self.headers,
                                         data=self.data,
                                         timeout=float(self.timeout),
                                         files=self.files,
                                         cookies=self.cookies)
                # MyLog.get_log().debug("文件上传 " + response.request.body)
                return response
            except TimeoutError:
                MyLog.get_log().error("Time out!")
                pass

        return response
Exemplo n.º 2
0
    def run(self):

        try:
            suit = self.set_case_suite()
            if suit is not None:
                MyLog.get_log().info(
                    "-------------------------测试开始-----------------------")
                report_path = os.path.abspath(
                    os.path.join(os.path.dirname(__file__), "report",
                                 "report.html"))
                fp = open(report_path, 'wb')
                runner = HTMLTestRunner.HTMLTestRunner(
                    stream=fp,
                    title='Interface Test Report',
                    description='jjj')
                runner.run(suit)  # 套件,为测试用例的有序集合
                fp.close()
            else:
                pass
        except Exception as ex:
            MyLog.get_log().error(str(ex))
        finally:
            MyLog.get_log().info(
                "-------------------------测试结束-----------------------")
Exemplo n.º 3
0
 def setUp(self) -> None:
     self.mylog = MyLog.get_log()
Exemplo n.º 4
0
 def setUp(self) -> None:
     self.dal = TestApiSpecialad()
     self.log = MyLog.get_log()
Exemplo n.º 5
0
 def setUp(self) -> None:
     self.dal = TestApiStatistics()
     self.mylog = MyLog.get_log()
Exemplo n.º 6
0
    def setUp(self) -> None:

        self.mylog = MyLog.get_log()
        self.dal = TestApiSubmitOrdergoodsComment()
Exemplo n.º 7
0
 def setUp(self) -> None:
     # self.dal = TestApiSpecialcms()  导入后直接用类属性
     self.mylog = MyLog.get_log()