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