def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Public_Api/updateQuote.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()
        self.caselist = self.filecontent.get_caselist()
        self.verify = Verify()
Beispiel #2
0
    def setUp(self):
        self.filename = Request().dirname() + "/Document/B_Client/getQuoteDetail.json"

        self.filecontent = FileContent(filename=self.filename)
        self.apiname = self.filecontent.get_apiname()
        self.caselist = self.filecontent.get_caselist()

        self.verify = Verify()
Beispiel #3
0
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/getBrokerOrderRefundList.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
Beispiel #4
0
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/**"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Public_Api/getAllBank.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist(
        )  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
Beispiel #6
0
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/queryBrokerOrderVoucher.json"
        # self.filename = os.path.abspath("../Document/Wechat_Applet/brokerGetCarSourceDetail.json")

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
Beispiel #7
0
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/brokerVerifyCodeLogin.json"
        # self.filename = os.path.abspath("../Document/Wechat_Applet/brokerVerifyCodeLogin")

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()
        self.api = self.filecontent.get_api()
        self.caselist = self.filecontent.get_caselist()

        self.verify = Verify()

        self.phone = "18867520068"
Beispiel #8
0
    def setUp(self):

        self.filename = Request().dirname() + "/Document/B_Client/publishBroker.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
        self.verificationErrors = []
Beispiel #9
0
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/B_Client/canPublishBrokerCarsrcList.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()
        self.api = self.filecontent.get_api()
        self.caselist = self.filecontent.get_caselist()

        self.verify = Verify()

        self.verificationError = []
Beispiel #10
0
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Wechat_Applet/sendValidataCode.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist(
        )  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
        self.verificationErrors = []
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Wechat_Applet/getVirtualOrderList.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist(
        )  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
        self.verificationErrors = []

        delete_sql = "DELETE FROM trans.trade_announcement_order"
        SqlOperation().delete_data(delete_sql)
Beispiel #12
0
class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/**"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        session = requests.session()
        response = session.post(url, timeout=1)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def test_get_success(self):
        """
        
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "ex"}
        for key, value in casenum.items():
            # print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))
            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult, result=json_result)

            print("ALL END!!")

    def tearDown(self):
        pass
    def get_manage_url(self, serial, filename, apiname):
        """
        请求参数在json文档中写死的
        :param serial: 
        :param filename: 
        :param apiname: 
        :return: 
        """
        params = FileContent(filename).get_reqparams(serial)
        params['source'] = self.source

        # 把source存入字典用于后续签名认证,格式source:123456
        # 把signature存入字典用于转换为url字符串,格式signature:1234567890
        signature = MD5().encodingpassword(maputil.get_signbase(params, self.separator) +
                                           MD5().encodingpassword(self.app_secret))
        params['signature'] = signature
        # 生成request_url
        url = self.manage_host + apiname + "?" + maputil.get_signbase(params, self.separator)

        print("url:", url)
        return url
class ConfirmBrokerOrder(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/confirmBrokerOrder.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        session = requests.session()
        response = session.post(url, timeout=1)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def test_confirm_success(self):
        """
        确认成交成功,购车证明和到店证明都上传图片
        校验点:1、data返回true
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "确认成交成功,购车证明和到店证明都上传图片"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))
            # 造数据,如果数据库中有这个单子,则删除后重新插入,用于确认成交
            sql_data = self.filecontent.get_sqldata(serial=key-1)
            if SqlOperation().select_data(sql_data['select_broker']) is not None:
                SqlOperation().delete_data(sql_data['delete_broker'])
            if SqlOperation().select_data(sql_data['select_oper']) is not None:
                SqlOperation().delete_data(sql_data['delete_oper'])
            SqlOperation().insert_data(sql_data['insert'])

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult, result=json_result)
            print("data verify is success.")

            print("ALL END!!")

    def test_confirm_success_nopic(self):
        """
        确认成交成功,未上传图片
        校验点:1、message:返回值 没有附件信息,请重新上传
        :return: 
        """
        time.sleep(2)
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {2: "确认成交成功,不上传图片"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))
            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select_broker']) is not None:
                SqlOperation().delete_data(sql_data['delete_broker'])
            if SqlOperation().select_data(sql_data['select_oper']) is not None:
                SqlOperation().delete_data(sql_data['delete_oper'])
            SqlOperation().insert_data(sql_data['insert'])

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print(json_result)
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            print("ALL END!!")

    def test_order_status_changed(self):
        """
        当提交成交确认时,订单状态发生变更,message提示
        校验点:1、message:返回值 订单状态已变更,请刷新后重试
        :return: 
        """
        # 设置等待时间,防止并发访问接口
        time.sleep(4)
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {3: "订单状态发生变更,提示信息"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))
            sql_data = self.filecontent.get_sqldata(serial=key-1)
            """
            if SqlOperation().select_data(sql_data['select']) == 0:
                SqlOperation().insert_data(sql_data['insert'])
            """
            SqlOperation().update_data(sql_data['update'])
            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            print("ALL END!!")

    def tearDown(self):
        SqlOperation().close()
Beispiel #15
0
class MyTestCase(unittest.TestCase):
    def setUp(self):

        self.filename = Request().dirname() + "/Document/B_Client/publishBroker.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
        self.verificationErrors = []

    def get_response(self, serial):
        """

            :param serial:
            :return: 获取接口返回
            """
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        session = requests.session()
        response = session.post(url)
        return response

    def test_publish_success(self):
        """
        经纪人带客车源发布成功
        校验点:1、data=成功
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "发布成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            response = self.get_response(serial=key - 1)
            self.verify.verify_code_200(response=response)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)

            self.verify.verify_data(expectresult=expectresult, result=json_result)
            print("ALL END!!")

    def test_modify_commission(self):
        """
        经纪人带客车源修改佣金成功
        校验点:1、data=成功
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {2: "修改佣金成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            response = self.get_response(serial=key - 1)
            self.verify.verify_code_200(response=response)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)

            self.verify.verify_data(expectresult=expectresult, result=json_result)
            print("ALL END!!")

    def test_cancel_publish(self):
        """
        经纪人带客车源取消发布成功
        校验点:1、data=成功
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {3: "取消发布成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            response = self.get_response(serial=key - 1)
            self.verify.verify_code_200(response=response)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)

            self.verify.verify_data(expectresult=expectresult, result=json_result)
            print("ALL END!!")

    def tearDown(self):
        pass
Beispiel #16
0
class QueryBrokerOrderVoucher(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/queryBrokerOrderVoucher.json"
        # self.filename = os.path.abspath("../Document/Wechat_Applet/brokerGetCarSourceDetail.json")

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        # self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        session = requests.session()
        response = session.post(url)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def test_confirmation(self):
        """
        查看确认成交详情
        校验点:1、校验data的返回值
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "确认成交详情"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key-1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key-1)))
            else:
                raise ValueError("TestCase {}'s instruction is not Equal to CaseNum.".format(key-1))
            response = self.get_response(serial=key-1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key-1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            self.verify.verify_data(expectresult=expectresult, result=json_result)

            print("ALL END!!")

    def tearDown(self):
        pass
Beispiel #17
0
class SaveBrokerUserFormId(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/saveBrokerUserFormId.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        session = requests.session()
        response = session.post(url, timeout=1)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def verify_formid_sql(self, serial):
        """
        校验请求后数据库是否有生成对应的formId记录
        :return: 
        """
        select_sql = self.filecontent.get_sqldata(serial)['select']
        self.assertEqual(SqlOperation().select_data(select_sql)[0], self.filecontent.get_reqparams(serial)['formId'],
                         msg="check sql db is Error.")

    def test_get_success(self):
        """
        小程序表单提交--保存form_id
        校验点:1、message:返回值 success
               2、请求后与数据库生成的记录做对比,form_id与请求参数的form_id保持一致
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "form_id保存成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select']) is not None:
                SqlOperation().delete_data(sql_data['delete'])

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            self.verify_formid_sql(serial=key - 1)

            print("ALL END!!")

    def tearDown(self):
        pass
Beispiel #18
0
class SaveCustomerServiceHandle(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Wechat_Applet/saveCustomerServiceHandle.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist(
        )  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial,
                                filename=self.filename,
                                apiname=self.apiname)
        session = requests.session()
        response = session.post(url, timeout=1)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def verify_oper_step_sql(self, serial):
        """
        校验oper_step_desc=经纪人申请申诉
        :param serial: 
        :return: 
        """
        select_sql = self.filecontent.get_sqldata(serial)['select_oper']
        oper_step_desc = SqlOperation().select_data(select_sql)
        self.assertIsNotNone(
            oper_step_desc,
            msg="经纪人申请申述后,trans.trade_oper_log表中oper_step_desc!='经纪人申请申诉'")

    def test_get_success(self):
        """
        经纪人客服申诉成功
        校验点:1、message:返回值 success
               2、申述成功后,trans.trade_oper_log多了一条记录,oper_step_desc=经纪人申请申诉
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "经纪人客服申诉成功"}
        for key, value in casenum.items():
            # print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key))
            """
            判断trans.trade_order_broker表订单车商是否申请退款refund_status=1,如果不是,则删除重新插入车商申请退款的订单;
            再判断trans.trade_oper_log表oper_step_desc是否存在“经纪人申请申诉”,如果有的话则删除,防止重复用此订单出现多个申述记录
            """
            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select_broker']) is None:
                SqlOperation().delete_data(sql_data['delete_broker'])
                SqlOperation().insert_data(sql_data['insert'])
            if SqlOperation().select_data(sql_data['select_oper']) is not None:
                SqlOperation().delete_data(sql_data['delete_oper'])
            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)

            self.verify_oper_step_sql(serial=key - 1)

            print("ALL END!!")

    def tearDown(self):
        SqlOperation().close()
class DeleteSearchLog(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/deleteSearchLog.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        session = requests.session()
        response = session.post(url, timeout=1)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def test_delete_success(self):
        """
        删除搜索记录成功
        校验点:1、message:返回值 删除搜索日志成功
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "删除搜索记录成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            """
            判断搜索记录是否存在于数据库中,如果不在则插入,
            如果在,判断status是否为0,如果不等于0,改成0即状态置为显示在搜索列表中
            """
            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select']) is not None:
                SqlOperation().insert_data(sql_data['insert'])
            else:
                if SqlOperation().select_data(sql_data['select'])[0] != 0:
                    SqlOperation().select_data('update')

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult, result=json_result)
            print("data verify is success.")

            print("ALL END!!")

    def tearDown(self):
        pass
Beispiel #20
0
class BrokerGetCarSourceDetail(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Wechat_Applet/unBindCard.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist(
        )  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial,
                                filename=self.filename,
                                apiname=self.apiname)
        session = requests.session()
        response = session.post(url, timeout=1)
        if response.status_code == 200:
            print(type(response))
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def test_unbind_success(self):
        """
        解绑银行卡,不管银行卡在数据库中是否存在,接口没做匹配,因为肯定是从list列表做的操作
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "解绑银行卡,不管银行卡在数据库中是否存在,接口没做匹配,因为肯定是从list列表做的操作"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key - 1))

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)
            self.verify.verify_code_200(response=response)

            print("api verify is beginning...")
            self.verify.verify_api(expectresult=expectresult,
                                   result=json_result)
            print("api verify is success.")

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)
            print("message verify is success.")

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)
            print("data verify is success.")

            print("ALL END!!")

    def check_sql(self):
        """
        可以查找数据库,解绑后数据库记录就没了,但是我现在没法区分车商钱包和经纪人钱包
        :return: 
        """
        pass

    def tearDown(self):
        pass
Beispiel #21
0
class SendValidataCode(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Wechat_Applet/sendValidataCode.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist(
        )  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        print(self.apiname)
        url = Request().get_url(serial=serial,
                                filename=self.filename,
                                apiname=self.apiname)
        # session = requests.session()
        response = requests.post(url)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError()

    def verify_received_mysql(self, serial):
        """
        校验数据库收到了验证码,只判断了最近的一条记录是发送的号码(号码从case获取)
        :param serial
        :return: 
        """
        sql = "SELECT * FROM auto.sms WHERE phone='{}' AND smstype='brokerUserLoginCode'"\
            .format(self.filecontent.get_reqparams(serial)['phone'])
        self.assertIsNotNone(SqlOperation().select_data(sql))

    def test_send_success(self):
        """
        成功发送验证码
        校验点:1、message:返回验证码已发送
               2、数据库收到了验证码
        :return: 
        """
        time.sleep(60)
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "验证码已发送,成功发送验证码"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "TestCase {}'s instruction is not Equal to CaseNum.".
                    format(key - 1))

            delete_sql = """
                                    DELETE FROM auto.sms WHERE phone='{}'
                            """.format(
                self.filecontent.get_reqparams(serial=key - 1)['phone'])
            SqlOperation().delete_data(sql=delete_sql)
            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)
            print("message verify is success.")

            self.verify_received_mysql(serial=key - 1)

            print("ALL END!!")

    def test_repeat_fail(self):
        """
        60s内仅能获取一次验证码
        校验点:1、message:60s内仅能获取一次验证码,请稍后再试
               2、code:返回值为20000
        :return: 
        """
        time.sleep(60)
        for num in range(len(self.caselist)):
            print("TestCase {}: {}".format(
                (num + 1), self.filecontent.get_instruction(serial=num)))
            try:
                operator.eq(self.caselist[num]['serial'], num + 1)
            except IOError:
                print("TestCase Number: {} Document is ERROR!".format(num + 1))
            finally:
                self.filecontent.get_instruction(serial=num)
                response = self.get_response(serial=num)
                json_result = response.json()
                print("response content: ", json_result)
                expectresult = self.filecontent.get_expectresult(serial=num)

                print("api verify is beginning...")
                self.verify.verify_api(expectresult=expectresult,
                                       result=json_result)
                print("api verify is success.")

                print("code verify is beginning...")
                self.verify.verify_code(expectresult=expectresult,
                                        result=json_result)
                print("code verify is success.")

                print("message verify is beginning...")
                self.verify.verify_message(expectresult=expectresult,
                                           result=json_result)
                print("message verify is success.")

                print("ALL END!!")

    def tearDown(self):
        SqlOperation().close()
class OrderEvaluate(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/orderEvaluate.json"
        # self.filename = os.path.abspath("../Document/Wechat_Applet/brokerGetCarSourceDetail.json")

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        # self.verificationErrors = []

    def get_response(self, serial):
        """
        
        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        session = requests.session()
        response = session.post(url)
        return response

    def test_evaluate_success(self):
        """
        小程序端经纪人佣金订单评价成功
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "小程序端经纪人佣金订单评价成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("TestCase {}'s instruction is not Equal to CaseNum.".format(key - 1))

            sql_data = self.filecontent.get_sqldata(serial=key-1)
            if sql_data['select'] is not None:
                SqlOperation().update_data(sql_data['update'])

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)
            self.verify.verify_code_200(response=response)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            print("ALL END!!")

    def tearDown(self):
        SqlOperation().close()
Beispiel #23
0
class CanPublishBrokerCarsrcList(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/B_Client/canPublishBrokerCarsrcList.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()
        self.api = self.filecontent.get_api()
        self.caselist = self.filecontent.get_caselist()

        self.verify = Verify()

        self.verificationError = []

    def get_response(self, serial):
        url = Request().get_url(serial=serial,
                                filename=self.filename,
                                apiname=self.apiname)
        session = requests.session()
        response = session.post(url)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError()

    def verify_publishBrokerStatus(self, serial, result):
        """
        校验response.datalist.publishBrokerStatus == expectResult.dataList.publishBrokerStatus
        :param serial: 
        :param result: 
        :return: 
        """
        param_datalist = self.filecontent.get_datalist(serial)
        param_status = []
        for i in range(len(param_datalist)):
            status = param_datalist[i]['publishBrokerStatus']
            if status not in param_status:
                param_status.append(status)
        for data in result['data']['dataList']:
            self.assertIn(
                data['publishBrokerStatus'],
                param_status,
                msg="The result dataList contains publishBrokerStatus {} != {}"
                .format(data['publishBrokerStatus'], param_status))

    def test_search_unrelease(self):
        """
        未发布车源,查询成功
        校验点:1、publishBrokerStatus,注意未发布状态请求参数publishBrokerStatus=2,而返回结果publishBrokerStatus=0 or 2
        请求结果在数据库company_car_source_order:`publish_broker_status`'发布到经纪人状态(0:未发布, 1: 发布, 2: 取消)',
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "未发布"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key))

            response = self.get_response(serial=key - 1)
            self.verify.verify_code_200(response=response)
            print(response.content)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)
            print("message verify is success.")

            self.verify_publishBrokerStatus(serial=key - 1, result=json_result)

            print("ALL END!!")

    def test_search_release(self):
        """
        已发布车源,查询成功
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {2: "已发布"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key))

            response = self.get_response(serial=key - 1)
            self.verify.verify_code_200(response=response)
            print(response.content)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)
            print("message verify is success.")

            self.verify_publishBrokerStatus(serial=key - 1, result=json_result)

            print("ALL END!!")
class GetVirtualOrderList(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Wechat_Applet/getVirtualOrderList.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist(
        )  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
        self.verificationErrors = []

        delete_sql = "DELETE FROM trans.trade_announcement_order"
        SqlOperation().delete_data(delete_sql)

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        if 'sql' in self.filecontent.get_caselist()[serial]:
            SqlOperation().insert_data(self.json_converto_sql(serial))
        url = Request().get_url(serial=serial,
                                filename=self.filename,
                                apiname=self.apiname)
        response = requests.post(url)
        return response

    def json_converto_sql(self, serial):
        """
        从json文件读取json格式的sql语句并转换为sql语句,只适用本脚本,如果数据表增加列了,这里也需要增加
        :param serial:
        :return:
        """
        sql_data = self.filecontent.get_sqldata(serial)
        print("sql_data: ", sql_data)
        sql = "\r\n" + "INSERT INTO trans.trade_announcement_order " \
                       "(id, order_no, broker_name, create_time, modify_time, commission_amount, source) VALUES \r\n"
        for i in range(len(sql_data)):
            data = sql_data[i]
            if i < len(sql_data) - 1:
                sql = sql + "('%s', '%s', '%s', '%s', '%s', '%s', '%s'),\r\n" % (
                    data['id'], data['order_no'], data['broker_name'],
                    data['create_time'], data['modify_time'],
                    data['commission_amount'], data['source'])
            else:
                sql = sql + "('%s', '%s', '%s', '%s', '%s', '%s', '%s');" % (
                    data['id'], data['order_no'], data['broker_name'],
                    data['create_time'], data['modify_time'],
                    data['commission_amount'], data['source'])
        print(sql)
        return sql

    def test_virtualorder_isNull(self):
        """
        当虚拟订单池为空,即虚拟订单数据库为空
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "当虚拟订单池为空,即虚拟订单数据库为空"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key))

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("api verify is beginning...")
            self.verify.verify_api(expectresult=expectresult,
                                   result=json_result)
            print("api verify is success.")

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)
            print("message verify is success.")

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)
            print("data verify is success.")

            print("ALL END!!")

    def test_get_virtualorder(self):
        """
        当虚拟订单池为空,即虚拟订单数据库为空
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {2: "当虚拟订单池中有数据,获取虚拟订单信息"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key))

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("api verify is beginning...")
            self.verify.verify_api(expectresult=expectresult,
                                   result=json_result)
            print("api verify is success.")

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)
            print("message verify is success.")

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)
            print("data verify is success.")

            print("ALL END!!")

    def tearDown(self):
        pass
Beispiel #25
0
class GetQuoteDetail(unittest.TestCase):

    def setUp(self):
        self.filename = Request().dirname() + "/Document/B_Client/getQuoteDetail.json"

        self.filecontent = FileContent(filename=self.filename)
        self.apiname = self.filecontent.get_apiname()
        self.caselist = self.filecontent.get_caselist()

        self.verify = Verify()
        # self.casenumber = self.filecontent.get_casenumber()

    def get_response(self, serial):
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        response = requests.post(url=url)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError()

    def verify_status(self, serial, result):
        """
        校验返回结果的status == auto.company_quote.status
        :param result
        :return: 
        """
        expect_status = self.filecontent.get_expectresult(serial)['status']
        result_status = result['data']['status']
        self.assertEqual(expect_status, result_status, msg="expect_status != result_status.")

    def test_offering(self):
        """
        报价中状态查询成功
        校验点:1、message:返回值 查询成功
               2、data不为空
               3、status=1
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "报价中状态查询成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            # 更新数据库auto.company_search_car的search_status、is_valid和auto.company_quote的status、is_valid状态
            sql = self.filecontent.get_sqldata(serial=key - 1)
            for sql_update in sql['update']:
                SqlOperation().update_data(sql_update)

            response = self.get_response(serial=key - 1)
            self.verify.verify_code_200(response=response)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)

            self.verify.verify_data_isNotNull(result=json_result)
            self.verify_status(serial=key - 1, result=json_result)

            print("ALL END!!")

    def test_offer_expired(self):
        """
        报价已过期状态查询成功
        校验点:1、message:返回值 查询成功
               2、data不为空
               3、status=2
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {2: "报价已过期状态查询成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            # 更新数据库auto.company_search_car的search_status、is_valid和auto.company_quote的status、is_valid状态
            sql = self.filecontent.get_sqldata(serial=key - 1)
            for sql_update in sql['update']:
                SqlOperation().update_data(sql_update)

            response = self.get_response(serial=key - 1)
            self.verify.verify_code_200(response=response)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)

            self.verify.verify_data_isNotNull(result=json_result)
            self.verify_status(serial=key-1, result=json_result)

            print("ALL END!!")

    def test_offer_withdraw(self):
        """
        报价已撤回状态查询成功
        校验点:1、message:返回值 查询成功
               2、data不为空
               3、status=3
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {3: "报价已撤回状态查询成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            # 更新数据库auto.company_search_car的search_status、is_valid和auto.company_quote的status、is_valid状态
            sql = self.filecontent.get_sqldata(serial=key - 1)
            for sql_update in sql['update']:
                SqlOperation().update_data(sql_update)

            response = self.get_response(serial=key - 1)
            self.verify.verify_code_200(response=response)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)

            self.verify.verify_data_isNotNull(result=json_result)
            self.verify_status(serial=key-1, result=json_result)

            print("ALL END!!")

    def test_offer_failure(self):
        """
        报价已失效   状态查询成功
        校验点:1、message:返回值 查询成功
               2、data不为空
               3、status=4
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {4: "报价已失效状态查询成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            # 更新数据库auto.company_search_car的search_status、is_valid和auto.company_quote的status、is_valid状态
            sql = self.filecontent.get_sqldata(serial=key - 1)
            for sql_update in sql['update']:
                SqlOperation().update_data(sql_update)

            response = self.get_response(serial=key - 1)
            self.verify.verify_code_200(response=response)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)

            self.verify.verify_data_isNotNull(result=json_result)
            self.verify_status(serial=key-1, result=json_result)

            print("ALL END!!")

    def tearDown(self):
        SqlOperation().close()
class QueryBrokerOrderPageList(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/queryBrokerOrderPageList.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"
        # self.casenumber = self.filecontent.get_casenumber()       # 获取case数量

        self.verify = Verify()
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        session = requests.session()
        response = session.post(url)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError()

    def verify_datalist_number(self, serial, result):
        """
        校验dataList列表长度,小于等于pagesize,即每次请求最多为pagesize规定的数值,默认为15
        :return: 
        """
        pagesize_parama = self.filecontent.get_reqparams(serial)['queryRequest']['pagesize']
        datalist = result['data']['dataList']
        len_datalist = len(datalist)
        self.assertTrue(len_datalist <= pagesize_parama,
                        msg="len_datalist: {}, pagesize: {}".format(len_datalist, pagesize_parama))

    def verify_status(self, serial, result):
        """
        校验status为当前查询列表的status
        :param serial: 
        :param result: 
        :return: 
        """
        expect_status = self.filecontent.get_datalist(serial)[0]['status']
        result_datalist = result['data']['dataList']
        for i in range(len(result_datalist)):
            self.assertEqual(expect_status, result_datalist[i]['status'])

    def test_to_pay(self):
        """
        待车商支付订单列表
        校验点:1、校验datalist列表长度<=pagesize的值
               2、校验datalist所有订单的status=0
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "待车商支付订单列表"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key-1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key-1)))
            else:
                raise ValueError("TestCase {}'s instruction is not Equal to CaseNum.".format(key-1))
            sql_data = self.filecontent.get_sqldata(serial=key-1)
            if SqlOperation().select_data(sql_data['select']) != 0:
                SqlOperation().delete_data(sql_data['delete'])
            SqlOperation().insert_data(sql_data['insert'])
            response = self.get_response(serial=key-1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key-1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            self.verify_datalist_number(serial=key - 1, result=json_result)
            self.verify_status(serial=key-1, result=json_result)

            print("ALL END!!")

    def test_broker_to_confirm(self):
        """
        待经纪人确认订单列表
        校验点:1、校验datalist列表长度<=pagesize的值
               2、校验datalist所有订单的status=1
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {2: "待经纪人确认订单列表"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("TestCase {}'s instruction is not Equal to CaseNum.".format(key - 1))
            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select']) != 0:
                SqlOperation().delete_data(sql_data['delete'])
            SqlOperation().insert_data(sql_data['insert'])
            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            self.verify_datalist_number(serial=key - 1, result=json_result)
            self.verify_status(serial=key - 1, result=json_result)

            print("ALL END!!")

    def test_customer_to_confirm(self):
        """
        待车商确认订单列表
        校验点:1、校验datalist列表长度<=pagesize的值
               2、校验datalist所有订单的status=2
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {3: "待车商确认订单列表"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("TestCase {}'s instruction is not Equal to CaseNum.".format(key - 1))
            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select']) is not None:
                SqlOperation().delete_data(sql_data['delete'])
            SqlOperation().insert_data(sql_data['insert'])
            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            self.verify_datalist_number(serial=key - 1, result=json_result)
            self.verify_status(serial=key - 1, result=json_result)

            print("ALL END!!")

    def test_paid_success(self):
        """
        交易成功订单列表
        校验点:1、校验datalist列表长度<=pagesize的值;
               2、校验datalist所有订单的status=3
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {4: "交易成功订单列表"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key-1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key-1)))
            else:
                raise ValueError("TestCase {}'s instruction is not Equal to CaseNum.".format(key-1))
            response = self.get_response(serial=key-1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key-1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            self.verify_datalist_number(serial=key - 1, result=json_result)
            self.verify_status(serial=key-1, result=json_result)

            print("ALL END!!")

    def test_paid_fail(self):
        """
        交易失败订单列表
        校验点:1、校验datalist列表长度<=pagesize的值
               2、校验datalist所有订单的status=3
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {5: "交易失败订单列表"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("TestCase {}'s instruction is not Equal to CaseNum.".format(key - 1))
            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            self.verify_datalist_number(serial=key - 1, result=json_result)
            self.verify_status(serial=key - 1, result=json_result)

            print("ALL END!!")

    def test_all_list(self):
        """
        全部订单列表
        校验点:1、校验datalist列表长度<=pagesize的值
               2、datalist不为空
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {6: "全部订单列表"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("TestCase {}'s instruction is not Equal to CaseNum.".format(key - 1))
            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            self.verify_datalist_number(serial=key-1, result=json_result)
            self.verify.verify_data_isNotNull(result=json_result)

            print("ALL END!!")

    def tearDown(self):
        SqlOperation().close()
class GetSearchLogList(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/getSearchLogList.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist()  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial, filename=self.filename, apiname=self.apiname)
        session = requests.session()
        response = session.post(url, timeout=1)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def verify_data_sql(self, serial, result):
        """
        data:从数据库取query_value值用于校验
        :param serial
        :param result
        :return: 
        """
        select_sql = self.filecontent.get_sqldata(serial)['select']
        select_result = SqlOperation().select_data_all(select_sql)
        verify_data = []
        if select_result is None:
            self.assertIsNone(result['data'], msg="result data is not NULL.")
        else:
            for data in select_result:
                verify_data.append(data[0])
            self.assertEqual(sorted(verify_data), sorted(result['data']))

    def test_get_success(self):
        """
        获取车源搜索记录
        校验点:1、message:返回值 查询搜索记录成功
               2、data:从数据库取query_value值用于校验
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "获取车源搜索记录"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            """
            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data_all(sql_data['select']) is None:
                SqlOperation().update_data(sql_data['update'])
            """

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            self.verify_data_sql(serial=key - 1, result=json_result)

            print("ALL END!!")

    def tearDown(self):
        pass
class GetIdentityInfo(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Wechat_Applet/getIdentityInfo.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist(
        )  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial,
                                filename=self.filename,
                                apiname=self.apiname)
        session = requests.session()
        response = session.post(url, timeout=1)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def verify_auth_status(self, serial, result):
        """
        校验auth_status=0
        :return: 
        """
        expect = self.filecontent.get_data(serial)["authStatus"]
        result = result["data"]["authStatus"]
        self.assertEqual(
            expect,
            result,
            msg="The expect authStatus: {}, the result authStatus: {}".format(
                expect, result))

    def test_status_unauthorized(self):
        """
        未认证状态
        校验点:1、从数据库获取对应userid的auth_status=0
               2、message:返回值 获取认证信息成功
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "未认证状态"}
        for key, value in casenum.items():
            # print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key))

            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select']) is None:
                SqlOperation().insert_data(sql_data['insert'])

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)

            print("authStatus verify is begining...")
            self.verify_auth_status(serial=key - 1, result=json_result)

            print("ALL END!!")

    def test_status_success(self):
        """
        认证成功状态
        校验点:1、从数据库获取对应userid的auth_status=1
               2、message:返回值 获取认证信息成功
               3、data返回的内容
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {2: "认证成功状态"}
        for key, value in casenum.items():
            # print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key))

            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select']) is None:
                SqlOperation().insert_data(sql_data['insert'])

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)

            print("authStatus verify is begining...")
            self.verify_auth_status(serial=key - 1, result=json_result)

            print("ALL END!!")

    def test_status_fail(self):
        """
        认证失败状态
        校验点:1、从数据库获取对应userid的auth_status=2
               2、message:返回值 获取认证信息成功
               3、data返回的内容
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {3: "认证失败状态"}
        for key, value in casenum.items():
            # print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key))

            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select']) is None:
                SqlOperation().insert_data(sql_data['insert'])

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)

            print("authStatus verify is begining...")
            self.verify_auth_status(serial=key - 1, result=json_result)

            print("ALL END!!")

    def test_status_ing(self):
        """
        认证中状态
        校验点:1、从数据库获取对应userid的auth_status=3
               2、message:返回值 获取认证信息成功
               3、data返回的内容
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {4: "认证中状态"}
        for key, value in casenum.items():
            # print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key))

            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if SqlOperation().select_data(sql_data['select']) is None:
                SqlOperation().insert_data(sql_data['insert'])

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)

            print("authStatus verify is begining...")
            self.verify_auth_status(serial=key - 1, result=json_result)

            print("ALL END!!")

    def tearDown(self):
        SqlOperation().close()
Beispiel #29
0
class BindCard(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Wechat_Applet/bindCard.json"

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()  # 获取apiname用于获得url
        self.api = self.filecontent.get_api()  # 获取api用于校验
        self.caselist = self.filecontent.get_caselist(
        )  # 获取caselist列表,包括"reqParams"和"expectResult"

        self.verify = Verify()
        # self.result = GlobalVar().global_dic
        self.verificationErrors = []

    def get_response(self, serial):
        """

        :param serial:
        :return: 获取接口返回
        """
        url = Request().get_url(serial=serial,
                                filename=self.filename,
                                apiname=self.apiname)
        session = requests.session()
        response = session.post(url, timeout=1)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError("request is refused.")

    def verify_reason(self, serial, result):
        """
        校验data里面的reason字段
        :param serial: key-1
        :param result: response.json()
        :return: 
        """
        ex_reason = self.filecontent.get_expectresult(
            serial=serial)['data']['reason']
        r_reason = result['data']['reason']
        self.assertEqual(ex_reason,
                         r_reason,
                         msg="TestCase {}: {} reason verify is Fail.".format(
                             serial + 1,
                             self.filecontent.get_instruction(serial - 1)))

    def verify_success(self, serial, result):
        """
        校验data里面的success字段
        :param serial: 
        :param result: 
        :return: 
        """
        ex_success = self.filecontent.get_expectresult(
            serial=serial)['data']['success']
        r_success = result['data']['success']
        self.assertEqual(ex_success,
                         r_success,
                         msg="TestCase {}: {} reason verify is Fail.".format(
                             serial + 1,
                             self.filecontent.get_instruction(serial - 1)))

    def test_four_elem_cert_false(self):
        """
        四要素认证不通过:绑定银行卡,四要素不一致,绑卡失败
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {1: "四要素认证不通过:绑定银行卡,四要素不一致,绑卡失败"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum."
                    .format(key - 1))

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key - 1)
            self.verify.verify_code_200(response=response)

            print("api verify is beginning...")
            self.verify.verify_api(expectresult=expectresult,
                                   result=json_result)
            print("api verify is success.")

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)
            print("message verify is success.")

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)
            print("data verify is success.")

            print("reason verify is begining...")
            self.verify_reason(serial=key - 1, result=json_result)
            print("reason verify is success.")

            print("success verify is begining...")
            self.verify_reason(serial=key - 1, result=json_result)
            print("success verify is success.")

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)
            print("data verify is success.")

            print("ALL END!!")

    def test_cert_success(self):
        """
        绑卡成功:前提条件-我的银行卡没有银行卡,四要素认证成功
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {2: "绑卡成功:前提条件-我的银行卡没有银行卡,四要素认证成功"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "TestCase {}'s instruction is not Equal to CaseNum.".
                    format(key - 1))

            sql_data = self.filecontent.get_sqldata(serial=key - 1)
            if len(SqlOperation().select_data(sql_data['select'])) == 1:
                SqlOperation().delete_data(sql_data['delete'])

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)

            expectresult = self.filecontent.get_expectresult(serial=key - 1)
            self.verify.verify_code_200(response=response)

            print("api verify is beginning...")
            self.verify.verify_api(expectresult=expectresult,
                                   result=json_result)
            print("api verify is success.")

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)
            print("message verify is success.")

            print("data verify is beginning...")
            self.verify.verify_data(expectresult=expectresult,
                                    result=json_result)
            print("data verify is success.")

            print("reason verify is begining...")
            self.verify_reason(serial=key - 1, result=json_result)
            print("reason verify is success.")

            print("success verify is begining...")
            self.verify_reason(serial=key - 1, result=json_result)
            print("success verify is success.")

            print("ALL END!!")

    def test_repeat_card(self):
        """
        重复绑卡:前提条件-我的银行卡列表已经绑定了银行卡
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {3: "重复绑卡:前提条件-我的银行卡列表已经绑定了银行卡"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key - 1))
            if operator.eq(value,
                           self.filecontent.get_instruction(serial=key - 1)):
                print("TestCase {}: {}".format(
                    key, self.filecontent.get_instruction(serial=key - 1)))
            else:
                raise ValueError(
                    "TestCase {}'s instruction is not Equal to CaseNum.".
                    format(key - 1))

            response = self.get_response(serial=key - 1)
            json_result = response.json()
            print("response content: ", json_result)

            expectresult = self.filecontent.get_expectresult(serial=key - 1)
            self.verify.verify_code_200(response=response)

            print("api verify is beginning...")
            self.verify.verify_api(expectresult=expectresult,
                                   result=json_result)
            print("api verify is success.")

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult,
                                    result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult,
                                       result=json_result)
            print("message verify is success.")

            print("ALL END!!")

    def tearDown(self):
        pass
Beispiel #30
0
class BrokerVerifyCodeLogin(unittest.TestCase):

    def setUp(self):
        self.filename = Request().dirname() + "/Document/Wechat_Applet/brokerVerifyCodeLogin.json"
        # self.filename = os.path.abspath("../Document/Wechat_Applet/brokerVerifyCodeLogin")

        self.filecontent = FileContent(self.filename)
        self.apiname = self.filecontent.get_apiname()
        self.api = self.filecontent.get_api()
        self.caselist = self.filecontent.get_caselist()

        self.verify = Verify()

        self.phone = "18867520068"

    def get_url(self, requestparam):
        """
        创建会话,获取response
        :param requestparam:
        :return:
        """
        dic = dict()
        dic['requestParam'] = requestparam
        dic['source'] = int(Request().get_source())
        signature = MD5().encodingpassword(MapUtil().get_signbase(dic, Request.separator()) +
                                           MD5().encodingpassword(Request.get_app_secret()))
        dic["signature"] = signature
        url = Request().get_host() + self.apiname + "?" + MapUtil().get_signbase(dic, Request.separator())
        print("url: ", url)
        return url

    def get_success_response(self):
        """
        serial为0时,获取验证码登陆
        :param serial:
        :return:
        """
        requestParam = {
            "cellphone": self.phone,
            "verifyCode": self.get_verify_code(),
            "code": ""
        }
        response = requests.post(self.get_url(requestParam))
        return response

    def get_response(self, serial):
        """
        从json文件中读取请求参数
        :param serial:
        :return:
        """
        url = Request().get_url(serial=serial, apiname=self.apiname, filename=self.filename)
        response = requests.post(url)
        if response.status_code == 200:
            return response
        else:
            raise ConnectionRefusedError()

    @staticmethod
    def sendvaliddatacode():
        """
        sendValiddataCode
        :return:
        """
        reqparams = "http://10.10.13.75:8080/dealer/sendvalidatecode.json?" \
                    "invokeType=20&phone=18867520068&signature=589f9e341eca8079f33e80adb3b7b3b3&source=123456"
        # sendvalidatacode_url = Request().get_host() + self.apiname + "?" + reqparams
        r = requests.post(url=reqparams)
        if r.json()['message'] == "验证码已发送":
            print("验证码已发送")
        else:
            print("sendValidataCode response is ", r.json())
            raise ConnectionError("The api sendValidataCode response is error. %s" % r.json())

    def get_verify_code(self):
        time.sleep(60)
        self.sendvaliddatacode()
        sql = """
                SELECT code FROM auto.sms WHERE phone='18867520068' AND smstype='brokerUserLoginCode' 
                ORDER BY sendtime DESC LIMIT 1
            """
        code = SqlOperation().select_data(sql=sql)[0]
        if len(code) == 6:
            print("get verify code is ", code)
            return code
        else:
            raise ValueError("The verify code is Error. Please check the sendvalidatacode api is OK.", code)

    def test_login_success(self):
        print("TestCase 1:")
        json_result = self.get_success_response().json()
        expectresult = self.filecontent.get_expectresult(serial=0)
        print("result: ", json_result)
        self.assertEqual(expectresult['code'], json_result['code'], msg="Code is Error, result = %s."
                                                                        % json_result)
        self.assertEqual(expectresult['message'], json_result['message'], msg="Message is Error, result = %s."
                                                                              % json_result['message'])
        self.assertEqual(expectresult['data'], json_result['data'],
                         msg="Data is Error, result = {}." .format(json_result))
        print("Test Login Success is OK.")

    def test_login_fail(self):
        """
        登陆失败,验证码过期
        :return: 
        """
        # casenum = {serial: instruction}, 如果与json文档不一致的话就会报错
        casenum = {2: "登陆失败,验证码过期/错误"}
        for key, value in casenum.items():
            print(value, self.filecontent.get_instruction(serial=key-1))
            if operator.eq(value, self.filecontent.get_instruction(serial=key-1)):
                print("TestCase {}: {}".format(key, self.filecontent.get_instruction(serial=key-1)))
            else:
                raise ValueError("用例匹配失败:TestCase {}'s instruction is not Equal to CaseNum.".format(key))

            delete_sql = """
                                                DELETE FROM auto.sms WHERE phone='{}'
                                        """.format(self.filecontent.get_reqparams(serial=key - 1)['phone'])
            SqlOperation().delete_data(sql=delete_sql)

            response = self.get_response(serial=key-1)
            self.verify.verify_code_200(response=response)
            print(response.content)
            json_result = response.json()
            print("response content: ", json_result)
            expectresult = self.filecontent.get_expectresult(serial=key-1)

            print("api verify is beginning...")
            self.verify.verify_api(expectresult=expectresult, result=json_result)
            print("api verify is success.")

            print("code verify is beginning...")
            self.verify.verify_code(expectresult=expectresult, result=json_result)
            print("code verify is success.")

            print("message verify is beginning...")
            self.verify.verify_message(expectresult=expectresult, result=json_result)
            print("message verify is success.")

            print("ALL END!!")

    def tearDown(self):
        SqlOperation().close()