def test_analyze_statement_two_channel_zfb(self): """FTP服务器上存在两条相同渠道的对账单(多个通道商户号同一渠道解析测试)# 每个渠道都要覆盖 验证解析完成后入库数据正确""" zfb_path = Constants.STATEMENT.zfb_path zfb2_path = Constants.STATEMENT.zfb2_path self.path_name = FtpConnect().push_file_csv_on_ftp(zfb_path) self.path2_name = FtpConnect().push_file_csv_on_ftp(zfb2_path) yesterday = str(datetime.date.today() - datetime.timedelta(days=1)).replace('-', '') PreconditionDowStatement.creat_download_info(Constants.CHANNEL.zfb, self.path_name, yesterday, 'zfb') PreconditionDowStatement.creat_download_info(Constants.CHANNEL.zfb2, self.path2_name, yesterday, 'zfb', id='99998') PreconditionDowStatement.statement_analyze_send(yesterday) befor_len = PreconditionDowStatement.get_csv_len( zfb_path) + PreconditionDowStatement.get_csv_len(zfb2_path) after_len = PreconditionDowStatement.select_count_mch_details() after_into_data = PreconditionDowStatement.select_into_data() self.assertEqual(befor_len, after_len, msg='对账单解析数据错误,CSV文件条目数为%s db查询出来的条目数为%s' % (befor_len, after_len)) self.assertEqual('1', after_into_data, msg='对账单解析标志改变出现错误,预期应该为1,实际为%s' % after_into_data) FtpConnect().delete_file(self.path2_name)
def clear_ftp_file(): """清理ftp的文件""" f = FtpConnect() csv_name_list, csv_type_list, index = PreconditionDowStatement.get_csv_name_from_db() if len(csv_name_list) == 0: return for name in csv_name_list: f.delete_file(name)
def creat_settle_data(self, channel='zfb'): """传入不同的channel""" kwargs = {'zfb': [Constants.CHANNEL.zfb, 'zfb', Constants.RECONCILIATION.true_zfb_path]} CreatReconciliation().zfb_in_transit_true_data() # 制造对平的在途数据 path_name = FtpConnect().push_file_csv_on_ftp(kwargs[channel][2]) PreconditionDowStatement.creat_download_info(kwargs[channel][0], path_name, '20200519', kwargs[channel][1]) PreconditionDowStatement.statement_analyze_send() PreconditionDowStatement.recondition()
def test_dow_load_statement_repeat(self): """重复拉取对账单校验""" file_list, file_number = PreconditionDowStatement.get_file_number_for_ftp() # 请求前获取对账单的数量和名称 PreconditionDowStatement.send_request() # 发起下载对账单请求,拉取6种不同渠道的对账单 day默认为前一天 PreconditionDowStatement.send_request() # 第二次发起下载对账单请求,拉取6种不同渠道的对账单 day默认为前一天 file_list_af, file_number_af = PreconditionDowStatement.get_file_number_for_ftp() # 请求后获取对账单的数量和名称 end_list = [i for i in file_list_af if i not in file_list] # 去重后的名称 befor_data = DownloadStatement.info_assert_kwargs(ftp_name=end_list, ftp_number=6, db_number=6, db_type=['cib', 'yl', 'zfb', 'wx', 'qq', 'dlb']) end_file_number = int(file_number_af) - int(file_number) # 增加对账单的数量 csv_name_list_af, csv_type_list_af, file_number_after = PreconditionDowStatement.get_csv_name_from_db() # 请求后的名称列表和类型列表 file_size_list = PreconditionDowStatement.get_file_list_size(csv_name_list_af) after_data = DownloadStatement.info_assert_kwargs(ftp_name=csv_name_list_af, ftp_number=end_file_number, db_number=file_number_after, db_type=csv_type_list_af, file_size=file_size_list) HandleDowStatement.assert_dow_statement(self, **{'befor_data': befor_data, 'after_data': after_data})
def test_analyze_statement_info_data_true(self): """FTP服务器上有对账单,数据库dowloadinfo表中该条记录为1时,解析对账单(正常流程,测试解析完成后是否能重复解析)""" zfb_path = Constants.STATEMENT.zfb_path self.path_name = FtpConnect().push_file_csv_on_ftp(zfb_path) yesterday = str(datetime.date.today() - datetime.timedelta(days=1)).replace('-', '') PreconditionDowStatement.creat_download_info(Constants.CHANNEL.zfb, self.path_name, yesterday, 'zfb') PreconditionDowStatement.update_into_data() PreconditionDowStatement.statement_analyze_send(yesterday) after_len = PreconditionDowStatement.select_count_mch_details() after_into_data = PreconditionDowStatement.select_into_data() self.assertEqual(0, after_len, msg='对账单解析数据错误,CSV文件条目数为%s db查询出来的条目数为%s' % (0, after_len)) self.assertEqual('1', after_into_data, msg='对账单解析标志改变出现错误,预期应该为1,实际为%s' % after_into_data)
def test_dow_load_statement_tomorrow(self): """拉取对账单校验 日期为明天""" file_list, file_number = PreconditionDowStatement.get_file_number_for_ftp() # 请求前获取对账单的数量和名称 tomorrow = str(datetime.date.today() + datetime.timedelta(days=1)).replace('-', '') PreconditionDowStatement.send_request(day=tomorrow) # 发起下载对账单请求,拉取6种不同渠道的对账单 day为明天 file_list_af, file_number_af = PreconditionDowStatement.get_file_number_for_ftp() # 请求后获取对账单的数量和名称 end_list = [i for i in file_list_af if i not in file_list] # 去重后的名称 befor_data = DownloadStatement.info_assert_kwargs(ftp_name=end_list, ftp_number=0, db_number=0, db_type=[]) end_file_number = int(file_number_af) - int(file_number) # 增加对账单的数量 csv_name_list_af, csv_type_list_af, file_number_after = PreconditionDowStatement.get_csv_name_from_db() # 请求后的名称列表和类型列表 file_size_list = PreconditionDowStatement.get_file_list_size(csv_name_list_af) after_data = DownloadStatement.info_assert_kwargs(ftp_name=csv_name_list_af, ftp_number=end_file_number, db_number=file_number_after, db_type=csv_type_list_af, file_size=file_size_list) HandleDowStatement.assert_dow_statement(self, **{'befor_data': befor_data, 'after_data': after_data})
def test_dow_load_statement_mouth(self): """拉取一个月之前的对账单校验""" file_list, file_number = PreconditionDowStatement.get_file_number_for_ftp() # 请求前获取对账单的数量和名称 mouth = str(datetime.date.today() - datetime.timedelta(days=30)).replace('-', '') PreconditionDowStatement.send_request(day=mouth) # 发起下载对账单请求,拉取6种不同渠道的对账单 day默认为前一天 file_list_af, file_number_af = PreconditionDowStatement.get_file_number_for_ftp() # 请求后获取对账单的数量和名称 end_list = [i for i in file_list_af if i not in file_list] # 去重后的名称 befor_data = DownloadStatement.info_assert_kwargs(ftp_name=end_list, ftp_number=6, db_number=6, db_type=['cib', 'yl', 'zfb', 'wx', 'qq', 'dlb']) end_file_number = int(file_number_af) - int(file_number) # 增加对账单的数量 csv_name_list_af, csv_type_list_af, file_number_after = PreconditionDowStatement.get_csv_name_from_db() # 请求后的名称列表和类型列表 file_size_list = PreconditionDowStatement.get_file_list_size(csv_name_list_af) after_data = DownloadStatement.info_assert_kwargs(ftp_name=csv_name_list_af, ftp_number=end_file_number, db_number=file_number_after, db_type=csv_type_list_af, file_size=file_size_list) HandleDowStatement.assert_dow_statement(self, **{'befor_data': befor_data, 'after_data': after_data})
def test_analyze_statement_flow_pass(self, zfb_path): """FTP服务器上有对账单,数据库dowloadinfo表中该条记录为0时,解析对账单(正常流程,测试解析数据时是否正确入库)""" log.info('开始执行解析%s对账单测试' % (zfb_path[1])) self.path_name = FtpConnect().push_file_csv_on_ftp(zfb_path[0]) yesterday = str(datetime.date.today() - datetime.timedelta(days=1)).replace('-', '') PreconditionDowStatement.creat_download_info(zfb_path[2], self.path_name, yesterday, zfb_path[1]) PreconditionDowStatement.statement_analyze_send(yesterday) befor_len = PreconditionDowStatement.get_csv_len(zfb_path[0]) after_len = PreconditionDowStatement.select_count_mch_details() after_into_data = PreconditionDowStatement.select_into_data() self.assertEqual(befor_len, after_len, msg='%s对账单解析数据错误,CSV文件条目数为%s db查询出来的条目数为%s' % (zfb_path[1], befor_len, after_len)) self.assertEqual('1', after_into_data, msg='对账单解析标志改变出现错误,预期应该为1,实际为%s' % after_into_data)
def test_analyze_statement(self): """FTP服务器上无对账单,数据库存在记录时,解析对账单(ftp误删)支付宝""" zfb_path = Constants.STATEMENT.none_zfb_path self.path_name = FtpConnect().push_file_csv_on_ftp(zfb_path) yesterday = str(datetime.date.today() - datetime.timedelta(days=1)).replace('-', '') PreconditionDowStatement.creat_download_info(Constants.CHANNEL.zfb, self.path_name, yesterday, 'zfb') PreconditionDowStatement.statement_analyze_send(yesterday) befor_len = PreconditionDowStatement.get_csv_len(zfb_path) after_len = PreconditionDowStatement.select_count_mch_details() after_into_data = PreconditionDowStatement.select_into_data() self.assertEqual(befor_len, after_len, msg='对账单解析数据错误,CSV文件条目数为%s db查询出来的条目数为%s' % (befor_len, after_len)) self.assertEqual(None, after_into_data, msg='对账单解析标志改变出现错误,预期应该为1,实际为%s' % after_into_data)
def test_zfb_reconciliation_true(self): """支付宝对平测试用例集合""" CreatReconciliation().zfb_in_transit_true_data() # 制造对平的在途数据 zfb_path = Constants.RECONCILIATION.true_zfb_path # 获取对账单数据 path_name = FtpConnect().push_file_csv_on_ftp(zfb_path) PreconditionDowStatement.creat_download_info(Constants.CHANNEL.zfb, path_name, '20200519', 'zfb') PreconditionDowStatement.statement_analyze_send() PreconditionDowStatement.recondition() expect = CreatReconciliation.info_assert_kwargs(trans_fee='87', recon_amt=27413, account_type='Y', info_len=0, info_list=[]) actual = PreconditionReconciliation.info_assert_kwargs_actual() Handle.machaccnt_handle_assert(self, expect, actual)
def test_dlb_reconciliation_false(self): """dlb对不平测试用例""" CreatReconciliation().dlb_in_transit_data() # 制造记账退款在途数据 zfb_path = Constants.RECONCILIATION.false_dlb_path # 获取对账单数据 path_name = FtpConnect().push_file_csv_on_ftp(zfb_path) PreconditionDowStatement.creat_download_info(Constants.CHANNEL.dlb, path_name, '20200519', 'dlb') PreconditionDowStatement.statement_analyze_send() PreconditionDowStatement.recondition() expect = CreatReconciliation.info_assert_kwargs( trans_fee='280', recon_amt=85820, account_type='N', info_len=10, info_list=['2', '0', '0', '2', '1', '1', '1', '1', '1', '1']) actual = PreconditionReconciliation.info_assert_kwargs_actual() Handle.machaccnt_handle_assert(self, expect, actual)