Skip to content

Commit aed29bb

Browse files
author
Hong-Thai Nguyen
authored
Merge pull request #12 from thaichat04/comment-parsing
Comment parsing
2 parents 0afa54e + 31b88b3 commit aed29bb

File tree

3 files changed

+16
-32
lines changed

3 files changed

+16
-32
lines changed

cfonb/parser/statement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def parse(self, file_obj):
4949
break
5050
else:
5151
row.update(new_row)
52-
comment = line.split(' ')[2].strip()
52+
comment = line[46:].strip()
5353
if comment:
5454
row['comment'] = row.get('comment', '') + (BR_LINE if row.get('comment', '') else '') + comment
5555
elif line[0:2] == '07':

cfonb/tests/test_statement.py

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
class TestStatement(unittest.TestCase):
1313

1414
def test_render_parse_cfonb(self):
15-
content = Statement().header('20002', '90005', 'EUR', '01711467640', date(2011, 10, 14), 12345.67)\
16-
.add('20002', '1234567', '90005', 'EUR', '01711467640', date(2011, 10, 14), 'label 1', 1234.56, 'reference1')\
17-
.add('20002', '1234567', '90005', 'EUR', '01711467640', date(2011, 10, 13), 'label 2', 123.45, 'reference2')\
15+
content = Statement().header('20002', '90005', 'EUR', '01717651230', date(2011, 10, 14), 12345.67)\
16+
.add('20002', '1234567', '90005', 'EUR', '01717651230', date(2011, 10, 14), 'label 1', 1234.56, 'reference1')\
17+
.add('20002', '1234567', '90005', 'EUR', '01717651230', date(2011, 10, 13), 'label 2', 123.45, 'reference2')\
1818
.render()
1919
print('content: {}'.format(content))
2020
reader = StatementReader()
2121
result = reader.parse(StringIO(content))
2222
for account in result:
2323
assert_is_not_none(account.account_nb)
24-
assert_equal(account.header.get('account_nb'), '01711467640')
24+
assert_equal(account.header.get('account_nb'), '01717651230')
2525
assert_equal(account.header.get('currency_code'), 'EUR')
2626
assert_equal(account.header.get('nb_of_dec'), '2')
2727
assert_equal(account.header.get('bank_code'), '20002')
@@ -36,35 +36,19 @@ def test_number_format(self):
3636
assert_equal(number_format(''), '')
3737

3838
def test_parse_with_original_content(self):
39-
content = '''0115589 29701EUR2 01711467640 220620GAEC DE STANG KERBAIL 0000000352431O0000
40-
0415589 29701EUR2E01711467640B1230620 220620PRLV ORANGE 0 0000000000315}VOTRE ABONNEMENT
41-
0515589 29701EUR2E01711467640B1230620 NBEORANGE
42-
0515589 29701EUR2E01711467640B1230620 LCCVOTRE ABONNEMENT FIXE 02XXXXX896 (FACTURE: XXXXX8960E2) - P
43-
0515589 29701EUR2E01711467640B1230620 RCN298576896 985768960E235E
44-
0515589 29701EUR2E01711467640B1230620 LIBPRELEVEMENTS SEPA DOMICILIES
45-
0715589 29701EUR2 01711467640 230620 0000000352746O '''
39+
content = '''0115589 29701EUR2 01717651230 220620AAAA BB CCCCC KERHHHH 0000000352431O0000
40+
0415589 29701EUR2E01717651230B1230620 220620PRLV AAAAAA 0 0000000000315}VOTRE ABONNEMENT
41+
0515589 29701EUR2E01717651230B1230620 YYYXXXXXX
42+
0515589 29701EUR2E01717651230B1230620 LCCVOTRE ABONNEMENT FIXE 02XXXXX896 (FACTURE: XXXXX8960E2) - P
43+
0515589 29701EUR2E01717651230B1230620 ABC683551768 777888999E111E
44+
0515589 29701EUR2E01717651230B1230620 LIBPRELEVEMENTS SEPA DOMICILIES
45+
0715589 29701EUR2 01717651230 230620 0000000352746O '''
4646
reader = StatementReader()
4747
result = reader.parse(StringIO(content))
4848
assert_equal(len(result[0].lines), 1)
49-
assert_true(result[0].lines[0].get('origin').startswith('0415589 29701EUR2E01711467640B1230620 220620PRLV ORANGE 0 0000000000315}VOTRE ABONNEMENT'))
50-
assert_true(result[0].lines[0].get('origin').endswith('0515589 29701EUR2E01711467640B1230620 LIBPRELEVEMENTS SEPA DOMICILIES '))
49+
assert_true(result[0].lines[0].get('origin').startswith('0415589 29701EUR2E01717651230B1230620 220620PRLV AAAAAA 0 0000000000315}VOTRE ABONNEMENT'))
50+
assert_true(result[0].lines[0].get('origin').endswith('0515589 29701EUR2E01717651230B1230620 LIBPRELEVEMENTS SEPA DOMICILIES '))
5151
assert_true(len(result[0].lines[0].get('origin').splitlines()) == 5)
52-
53-
def test_parse_with_comment_content(self):
54-
content = '''0115589 29701EUR2 01711467640 220620GAEC DE STANG KERBAIL 0000000352431O0000
55-
0415589 29701EUR2E01711467640B1230620 220620PRLV ORANGE 0 0000000000315}VOTRE ABONNEMENT
56-
0515589 29701EUR2E01711467640B1230620 NBEORANGE
57-
0515589 29701EUR2E01711467640B1230620 LCCVOTRE ABONNEMENT FIXE 02XXXXX896 (FACTURE: XXXXX8960E2) - P
58-
0515589 29701EUR2E01711467640B1230620 RCN298576896 985768960E235E
59-
0515589 29701EUR2E01711467640B1230620 LIBPRELEVEMENTS SEPA DOMICILIES
60-
0715589 29701EUR2 01711467640 230620 0000000352746O '''
61-
reader = StatementReader()
62-
result = reader.parse(StringIO(content))
63-
assert_equal(len(result[0].lines), 1)
64-
assert_true(result[0].lines[0].get('comment').startswith(
65-
'NBEORANGE'))
66-
assert_true(result[0].lines[0].get('comment').endswith(
67-
'LIBPRELEVEMENTS SEPA DOMICILIES'))
6852
assert_true(len(result[0].lines[0].get('comment').splitlines()) == 4)
6953

7054

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
version = '2.6'
3+
version = '2.7'
44

55
long_description = open('README.rst').read()
66

@@ -14,7 +14,7 @@
1414
author='Dhatim',
1515
author_email='[email protected]',
1616
url='https://github.com/dhatim/python-cfonb',
17-
download_url = 'https://github.com/dhatim/python-cfonb/archive/2.6.tar.gz',
17+
download_url = 'https://github.com/dhatim/python-cfonb/archive/2.7.tar.gz',
1818
license='LGPL',
1919
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
2020
include_package_data=True,

0 commit comments

Comments
 (0)