示例#1
0
class GetBrokerAllBank(unittest.TestCase):
    def setUp(self):
        self.filename = Request().dirname(
        ) + "/Document/Wechat_Applet/getBrokerAllBank.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_get_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))

            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("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
示例#2
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 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
示例#4
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
示例#5
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
示例#6
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()
class UpdateQuote(unittest.TestCase):
    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()

    def get_response(self, serial):
        url = Request().get_url(serial=serial,
                                filename=self.filename,
                                apiname=self.apiname)
        session = requests.session()
        response = session.post(url)
        return response

    def test_updatequote_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))

            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 test_change_commission(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)
            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 test_modify_inf(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))

            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!!")
示例#8
0
class GetBrokerOrderRefundList(unittest.TestCase):
    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()
        # 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 refuse.")

    def test_timed_task_refund(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_broker_agree_refund(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 test_customer_refund_to_broker(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))

            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_customer_refund_to_dealer(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))

            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