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