File: test.py

package info (click to toggle)
python-febelfin-coda 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212 kB
  • sloc: python: 680; sh: 9; makefile: 3
file content (322 lines) | stat: -rw-r--r-- 10,882 bytes parent folder | download
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/usr/bin/env python
# This file is part of febelfin-coda.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
"""Test MT940
"""
import os
import unittest
from datetime import date
from decimal import Decimal

from coda import CODA

here = os.path.dirname(__file__)


class TestCODA(unittest.TestCase):

    def setUp(self):
        self.coda = CODA(os.path.join(here, 'CODA.txt'))

    @property
    def statement(self):
        return self.coda.statements[0]

    @property
    def move(self):
        return self.statement.moves[0]

    def get_move(self, sequence, detail_sequence):
        return self.statement.find_move(sequence, detail_sequence)

    @property
    def information(self):
        return self.statement.informations['OL9456574JBBNEUBCRCL1'][0]

    def get_information(self, sequence, detail_sequence):
        for informations in self.statement.informations.values():
            for information in informations:
                if (information.sequence == sequence
                        and information.detail_sequence == detail_sequence):
                    return information

    def test_number_statements(self):
        self.assertEqual(len(self.coda.statements), 1)

    def test_statement_str(self):
        self.assertEqual(str(self.statement), '001')

    def test_statement_creation_date(self):
        self.assertEqual(self.statement.creation_date, date(2006, 12, 6))

    def test_statement_bank_id(self):
        self.assertEqual(self.statement.bank_id, 725)

    def test_statement_duplicate(self):
        self.assertEqual(self.statement.duplicate, False)

    def test_statement_file_reference(self):
        self.assertEqual(self.statement.file_reference, '00099449')

    def test_statement_address(self):
        self.assertEqual(self.statement.address, 'Testgebruiker21')

    def test_statement_bic(self):
        self.assertEqual(self.statement.bic, 'KREDBEBB')

    def test_statement_company_id(self):
        self.assertEqual(self.statement.company_id, '00630366277')

    def test_statement_version(self):
        self.assertEqual(self.statement.version, 2)

    def test_statement_old_sequence(self):
        self.assertEqual(self.statement.old_sequence, '001')

    def test_statement_new_sequence(self):
        self.assertEqual(self.statement.new_sequence, '001')

    def test_statement_account(self):
        self.assertEqual(self.statement.account, '435000000080')

    def test_statement_account_currency(self):
        self.assertEqual(self.statement.account_currency, 'EUR')

    def test_statement_account_country(self):
        self.assertEqual(self.statement.account_country, 'BE')

    def test_statement_old_balance(self):
        self.assertEqual(self.statement.old_balance, Decimal('0.000'))

    def test_statement_old_balance_date(self):
        self.assertEqual(self.statement.old_balance_date, date(2006, 12, 6))

    def test_statement_new_balance(self):
        self.assertEqual(self.statement.new_balance, Decimal('9405296.990'))

    def test_statement_new_balance_date(self):
        self.assertEqual(self.statement.new_balance_date, date(2006, 12, 7))

    def test_statement_account_holder_name(self):
        self.assertEqual(self.statement.account_holder_name, 'Testgebruiker21')

    def test_statement_account_description(self):
        self.assertEqual(
            self.statement.account_description, 'KBC-Bedrijfsrekening')

    def test_statement_coda_sequence(self):
        self.assertEqual(self.statement.coda_sequence, '001')

    def test_statement_number_records(self):
        self.assertEqual(self.statement.number_records, 260)

    def test_statement_total_debit(self):
        amount = sum(m.amount for m in self.statement.moves if m.amount < 0)
        self.assertEqual(self.statement.total_debit, -amount)

    def test_statement_total_credit(self):
        amount = sum(m.amount for m in self.statement.moves if m.amount > 0)
        self.assertEqual(self.statement.total_credit, amount)

    def test_statement_find(self):
        move = self.statement.find_move('0041', '0001')

        self.assertEqual(move.sequence, '0041')
        self.assertEqual(move.detail_sequence, '0001')

    def test_moves(self):
        self.assertEqual(len(list(self.statement.moves)), 59)

    def test_move_str(self):
        self.assertEqual(str(self.move), '00010000')

    def test_move_sequence(self):
        self.assertEqual(self.move.sequence, '0001')

    def test_move_detail_sequence(self):
        self.assertEqual(self.move.detail_sequence, '0000')

    def test_move_bank_reference(self):
        self.assertEqual(self.move.bank_reference, 'EPIB00048 AWIUBTKAPUO')

    def test_move_amount(self):
        self.assertEqual(self.move.amount, Decimal('-2578.25'))

    def test_move_value_date(self):
        self.assertEqual(self.move.value_date, date(2006, 12, 6))

    def test_move_transaction_code(self):
        self.assertEqual(self.move.transaction_code, '00799000')

    def test_move_transaction_type(self):
        self.assertEqual(self.move.transaction_type, '0')

    def test_move_transaction_family(self):
        self.assertEqual(self.move.transaction_family, '07')

    def test_move_transaction_transaction(self):
        self.assertEqual(self.move.transaction_transaction, '99')

    def test_move_transaction_category(self):
        self.assertEqual(self.move.transaction_category, '000')

    def test_move_communication_type(self):
        self.assertEqual(self.move.communication_type, None)

    def test_move_communication(self):
        self.assertEqual(
            self.move.communication,
            "BORDEREAU DE DECOMPTE AVANCES    015 NUMERO D'OPERATION 495953")

    def test_move_communication_101(self):
        move = self.get_move('0053', '0000')

        self.assertEqual(move.communication_type, '101')
        self.assertEqual(move.communication, '269021157996')

    def test_move_communication_105(self):
        move = self.get_move('0003', '0002')

        self.assertEqual(move.communication_type, '105')
        self.assertEqual(move.communication, '')

    def test_move_communication_106(self):
        move = self.get_move('0004', '0003')

        self.assertEqual(move.communication_type, '106')
        self.assertEqual(move.communication, None)

    def test_move_communication_111(self):
        move = self.get_move('0009', '0000')

        self.assertEqual(move.communication_type, '111')
        self.assertEqual(move.communication, None)

    def test_move_communication_113(self):
        move = self.get_move('0012', '0000')

        self.assertEqual(move.communication_type, '113')
        self.assertEqual(move.communication, None)

    def test_move_communication_114(self):
        move = self.get_move('0043', '0001')

        self.assertEqual(move.communication_type, '114')
        self.assertEqual(move.communication, None)

    def test_move_communication_115(self):
        move = self.get_move('0049', '0000')

        self.assertEqual(move.communication_type, '115')
        self.assertEqual(move.communication, None)

    def test_move_entry_date(self):
        self.assertEqual(self.move.entry_date, date(2006, 12, 6))

    def test_move_statement_number(self):
        self.assertEqual(self.move.statement_number, '001')

    def test_move_customer_reference(self):
        move = self.get_move('0004', '0000')

        self.assertEqual(move.customer_reference, 'NB2206092900135')

    def test_move_counterparty_bic(self):
        move = self.get_move('0006', '0000')

        self.assertEqual(move.counterparty_bic, 'CREGBEBB')

    def test_move_r_transaction(self):
        move = self.get_move('0003', '0000')

        self.assertEqual(move.r_transaction, '4')

    def test_move_r_reason(self):
        move = self.get_move('0003', '0000')

        self.assertEqual(move.r_reason, '3246')

    def test_move_category_purpose(self):
        move = self.get_move('0003', '0000')

        self.assertEqual(move.category_purpose, '306A')

    def test_move_purpose(self):
        move = self.get_move('0003', '0000')

        self.assertEqual(move.purpose, '1648')

    def test_move_counterparty_account(self):
        move = self.get_move('0003', '0000')

        self.assertEqual(move.counterparty_account, 'LU037050522702273100')

    def test_move_counterparty_name(self):
        move = self.get_move('0003', '0000')

        self.assertEqual(move.counterparty_name, ' Olgerdin Egill Skallagrims')

    def test_informations(self):
        self.assertEqual(len(self.statement.informations), 22)

    def test_information_str(self):
        self.assertEqual(str(self.information), '00030001')

    def test_information_sequence(self):
        self.assertEqual(self.information.sequence, '0003')

    def test_information_detail_sequence(self):
        self.assertEqual(self.information.detail_sequence, '0001')

    def test_information_bank_reference(self):
        self.assertEqual(
            self.information.bank_reference, 'OL9456574JBBNEUBCRCL1')

    def test_information_transaction_code(self):
        self.assertEqual(self.information.transaction_code, '34150000')

    def test_information_communitcation_type(self):
        self.assertEqual(self.information.communication_type, '001')

    def test_information_communitcation_name(self):
        self.assertEqual(self.information.name, 'Olgerdin Egill Skallagrims')

    def test_information_communitcation_street(self):
        self.assertEqual(self.information.street, 'Grjothalsi 7')

    def test_information_communitcation_locality(self):
        self.assertEqual(self.information.locality, '11110 Reykjavik')

    def test_information_communitcation_code_id(self):
        self.assertEqual(self.information.code_id, '')

    def test_information_counterparty_banker(self):
        information = self.get_information('0058', '0002')

        self.assertEqual(information.counterparty_banker, 'SOCIETE GENERALE')

    def test_information_coin_number(self):
        information = self.get_information('0049', '0001')

        self.assertEqual(information.coin_number, 1)

    def test_information_coin(self):
        information = self.get_information('0049', '0001')

        self.assertEqual(information.coin, Decimal('10'))

    def test_information_total_amount(self):
        information = self.get_information('0049', '0001')

        self.assertEqual(information.total_amount, Decimal('10'))

    def test_sum_moves(self):
        amount = sum(m.amount for m in self.statement.moves)
        self.assertEqual(
            amount, self.statement.new_balance - self.statement.old_balance)

    def test_sum_details(self):
        move = self.get_move('0002', '0000')
        amount = sum(m.amount for m in move.moves)

        self.assertEqual(amount, move.amount)