def test_addenda_rejection(): nacha = Parser().parse(large_file_with_addenda) rejection.addenda_rejection(nacha) assert not nacha.error_code assert all(batch.error_code is None for batch in nacha.batches) assert all(entry.error_code is None for batch in nacha.batches for entry in batch.entries) assert any(addenda.error_code is not None for batch in nacha.batches for entry in batch.entries for addenda in entry.addenda) rejected_lines = list(rejection.filter_rejection_lines(nacha.lines)) nacha = Parser.lines_to_nacha_file(rejected_lines) assert all(addenda.error_code is not None for batch in nacha.batches for entry in batch.entries for addenda in entry.addenda)
def filter_rejection_lines(lines): """ Filter lines to create a rejection only file. All parents or children of a rejected line are returned, :param lines: :return: """ nacha = Parser.lines_to_nacha_file(lines) if not nacha.error_code: for batch in list(nacha.batches): if not batch.error_code: for entry in list(batch.entries): if not entry.error_code: for addenda in list(entry.addenda): if not addenda.error_code: entry.addenda.remove(addenda) if not entry.addenda: batch.entries.remove(entry) if not batch.entries: nacha.batches.remove(batch) if not nacha.batches: return [nacha.file_header, nacha.file_control] return nacha.lines
def test_random_rejection(): for _ in range(100): # Run this a bunch of times since its random nacha = Parser().parse(large_file_with_addenda) rejection.random_reject(nacha) assert nacha.error_code or \ any(batch.error_code is not None for batch in nacha.batches) or \ any(entry.error_code is not None for batch in nacha.batches for entry in batch.entries) or \ any(addenda.error_code is not None for batch in nacha.batches for entry in batch.entries for addenda in entry.addenda)
def test_filtering_non_rejected_file_has_header_and_control(): nacha = Parser().parse(large_file_with_addenda) rejected_lines = list(rejection.filter_rejection_lines(nacha.lines)) assert 2 == len(rejected_lines)
"820000000200264279090000000050000000000000002222222222 091000010000002\n" "5200ABC COMPANY 1111111111PPDPREMIUM SEP 120909120001091000017000003\n" "6260841006385656565 00000039920001357 SHERYL S SMITH 1091000010333333\n" "799R07091000010333333 08410063 091000010003456\n" "820000000200084100630000000039920000000000001111111111 091000010000003\n" "5200ABC COMPANY 1111111111PPDPREMIUM SEP 120909120001091000017000004\n" "6261211330050120120120 00000000000001579 WAYNE WILSON 1091000010444444\n" "798C02091000010444444 12113300121140218 091000010004567\n" "820000000200121133000000000000000000000000001111111111 091000010000004\n" "5200ABC COMPANY 2222222222PPDPREMIUM SEP 120909120001091000017000005\n" "6260653054369898989898 00000000000002345 GEORGE GONZALES 1091000010555555\n" "798C05091000010555555 0653054337 091000010005678\n" "820000000200065305430000000000000000000000002222222221 091000010000005\n" "9000005000003000000100058631944000000010805000000000000") returns_parser = Parser(returns_file=True) def test_parse_lines_return_file(): assert list(returns_parser.parse_lines(large_returns_file)) def test_parse_return_file(): nacha = returns_parser.parse(large_returns_file) assert nacha.batch_count == 5 assert all(batch.entry_count == 1 for batch in nacha.batches) addenda_1 = nacha.batches[0].entries[0].addenda[0].entry_addenda addenda_2 = nacha.batches[1].entries[0].addenda[0].entry_addenda addenda_3 = nacha.batches[2].entries[0].addenda[0].entry_addenda addenda_4 = nacha.batches[3].entries[0].addenda[0].entry_addenda addenda_5 = nacha.batches[4].entries[0].addenda[0].entry_addenda