コード例 #1
0
    def test_1(self):

        #用例序号,对应excel表格中第几条用例的数据
        case_index = 1
        #从excel表格读取的接口用例信息,编号代表第几条用例
        excel_info = self.execExcel.get_info(self.interfaceId)[case_index]

        #接口用例为N则不执行直接成功
        if excel_info['exec'] in ['N', 'n']:
            self.logger.info('CaseTest.test_1:skip this use case!')
            return 'success'

        #从接口用例信息读取的断言信息,用于断言
        assert_code = excel_info['re-code']
        assert_msg = excel_info['re-msg']

        #封装一个GetRequestInfo类,用于获取接口参数信息
        getRequestInfo = GetRequestInfo(self.initial)
        url, headers, datas = getRequestInfo.get_post_info(
            self.interfaceId, excel_info)

        #执行POST请求
        response = self.s.post(url=url, data=datas, headers=headers)

        #写日志,并且根据response值做断言
        self.logger.info('Run case:CaseTest.test_1')
        try:
            self.assertEqual(str(response.json().get('code')), assert_code)
            interface_init.initial.result.append((case_index, 'success', 'OK'))
        #将错误异常捕获并抛出
        except AssertionError as e:
            interface_init.initial.result.append((case_index, 'Fail', str(e)))
            raise e
コード例 #2
0
    def test_interface11(self,excel_info):
        if excel_info =='placeholder':
            self.logger.info("CaseInterface11.test_interface11|data drivern:skip this placeholder case!")
            return True
        case_index=excel_info['case_index']

        #接口用例为N则不执行直接成功
        if excel_info['exec'] in ['N','n']:
            self.logger.info('CaseInterface11.test_interface11|data drivern:skip this use case!')
            return 'success'


        #从接口用例信息读取的断言信息,用于断言
        assert_code=excel_info.get("re-code",False)
        assert_tradeStatus=excel_info.get("re-tradeStatus",False)
        assert_accountFlag=excel_info.get("accountFlag",False)
        assert_bankFlag=excel_info.get("bankFlag",False)
        assert_pwdFlag=excel_info.get("pwdFlag",False)


        #封装一个GetRequestInfo类,用于获取接口参数信息
        getRequestInfo=GetRequestInfo(self.initial)
        url,headers,datas=getRequestInfo.get_post_info(self.interfaceId,excel_info)


        # 记录post出去的params
        self.logger.info('CaseInterface11.test_interface11 index {index} request is :{one}'.format(index=case_index,one=datas))
        #执行POST请求
        response=self.s.post(url=url,data=datas,headers=headers)

        # 记录返回的response
        self.logger.info("CaseInterface11.test_interface11 index {index} response is :{one}".format(index=case_index,one=response.text))

        try:
            if str(response.json().get("code"))!=assert_code:
                self.logger.info("CaseInterface12.test_interface12|re-code is {one};expection is {two}".format(one=str(response.json().get("code")),two=assert_code))
                interface_init.initial.result.append((case_index, 'Fail', response.text))
                return "Fail"
            #如果返回状态码不是200,则把msg写进日志里
            elif str(response.json().get("code"))==assert_code:
                if assert_code=="200":
                    self.assertEqual(str(eval(response.json().get('data')).get('tradeStatus')), assert_tradeStatus)
                    if assert_accountFlag not in [False, ""]:
                        self.assertEqual(str(eval(response.json().get('data')).get('accountFlag')), assert_accountFlag)

                    if assert_bankFlag not in [False, ""]:
                        self.assertEqual(str(eval(response.json().get('data')).get('bankFlag')),
                                         assert_bankFlag)

                    if assert_pwdFlag not in [False, ""]:
                        self.assertEqual(str(eval(response.json().get('data')).get('pwdFlag')),
                                         assert_pwdFlag)
                interface_init.initial.result.append((case_index, 'success', 'OK'))


        #将错误异常捕获并抛出
        except AssertionError as e:
            interface_init.initial.result.append((case_index,'Fail',str(e)))
            self.logger.info("CaseInterface12.test_interface12 index {index} error is {error}".format(index=case_index,error=str(e)))
            raise e
コード例 #3
0
    def test_interface09(self, excel_info):
        if excel_info == 'placeholder':
            self.logger.info(
                "CaseTest.test_interface08|data drivern:skip this placeholder case!"
            )
            return True

        case_index = excel_info['case_index']

        #接口用例为N则不执行直接成功
        if excel_info['exec'] in ['N', 'n']:
            self.logger.info(
                'CaseTest.test_interface09|data drivern:skip this use case!')
            return 'success'

        #从接口用例信息读取的断言信息,用于断言
        assert_code = excel_info['re-code']
        assert_msg = excel_info['re-msg']

        #封装一个GetRequestInfo类,用于获取接口参数信息
        getRequestInfo = GetRequestInfo(self.initial)
        url, headers, datas = getRequestInfo.get_post_info(
            self.interfaceId, excel_info)

        #执行POST请求
        response = self.s.post(url=url, data=datas, headers=headers)

        #写日志,并且根据response值做断言
        self.logger.info('Run case:CaseTest.test_interface09|data drivern')
        try:
            self.assertEqual(str(response.json().get('code')), assert_code)
            interface_init.initial.result.append((case_index, 'success', 'OK'))
        #将错误异常捕获并抛出
        except AssertionError as e:
            interface_init.initial.result.append((case_index, 'Fail', str(e)))
            self.logger.info(
                "Run case:CaseTest.test_interface09|data drivern error: %s" %
                str(e))
            raise e