1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
import os
import pathlib
import pytest
import mt940
_tests_path = pathlib.Path(__file__).parent
@pytest.fixture
def sta_data():
with (_tests_path / 'jejik' / 'abnamro.sta').open() as fh:
return fh.read()
@pytest.fixture
def february_30_data():
with (_tests_path / 'self-provided' / 'february_30.sta').open() as fh:
return fh.read()
def test_date_fixup_pre_processor(february_30_data):
transactions = mt940.models.Transactions(processors=dict(
pre_statement=[
mt940.processors.date_fixup_pre_processor,
],
))
transactions.parse(february_30_data)
assert transactions[0].data['date'] == mt940.models.Date(2016, 2, 29)
def test_parse_data():
with (_tests_path / 'jejik' / 'abnamro.sta').open() as fh:
mt940.parse(fh.read())
def test_parse_fh():
with (_tests_path / 'jejik' / 'abnamro.sta').open() as fh:
mt940.parse(fh)
def test_parse_filename():
path = 'mt940_tests/jejik/abnamro.sta'
path = path.replace('/', os.pathsep)
mt940.parse(path)
def test_pre_processor(sta_data):
transactions = mt940.models.Transactions(processors=dict(
pre_final_closing_balance=[
mt940.processors.add_currency_pre_processor('USD'),
],
pre_final_opening_balance=[
mt940.processors.add_currency_pre_processor('EUR'),
],
))
transactions.parse(sta_data)
assert transactions.data['final_closing_balance'].amount.currency == 'USD'
assert transactions.data['final_opening_balance'].amount.currency == 'EUR'
def test_post_processor(sta_data):
transactions = mt940.models.Transactions(processors=dict(
post_closing_balance=[
mt940.processors.date_cleanup_post_processor,
],
))
transactions.parse(sta_data)
assert 'closing_balance_day' not in transactions.data
@pytest.fixture
def mBank_mt942_data():
with (_tests_path / 'mBank' / 'mt942.sta').open() as fh:
return fh.read()
def test_mBank_processors(mBank_mt942_data):
transactions = mt940.models.Transactions(processors=dict(
post_transaction_details=[
mt940.processors.mBank_set_transaction_code,
mt940.processors.mBank_set_iph_id,
mt940.processors.mBank_set_tnr,
],
))
transaction = transactions.parse(mBank_mt942_data)[0].data
assert transaction['transaction_code'] == 911
assert transaction['iph_id'] == '000000000001'
assert transaction['tnr'] == '179171073864111.010001'
def test_transaction_details_post_processor_with_space():
filename = _tests_path / 'betterplace' / 'sepa_mt9401.sta'
transactions = mt940.parse(filename)
transaction2 = transactions[0].data
transactions = mt940.parse(filename, processors=dict(
post_transaction_details=[
mt940.processors.transaction_details_post_processor_with_space,
],
))
transaction = transactions[0].data
assert transaction2['end_to_end_reference'] != \
transaction['end_to_end_reference']
@pytest.fixture
def mBank_with_newline_in_tnr():
with (_tests_path / 'mBank' / 'with_newline_in_tnr.sta').open() as fh:
return fh.read()
def test_mBank_set_tnr_parses_tnr_with_newlines(mBank_with_newline_in_tnr):
transactions = mt940.models.Transactions(processors=dict(
post_transaction_details=[
mt940.processors.mBank_set_tnr,
],
))
transactions_ = transactions.parse(mBank_with_newline_in_tnr)
assert transactions_[0].data['tnr'] == '179301073837502.000001'
assert transactions_[1].data['tnr'] == '179301073844398.000001'
|