forked from gaugendre/ofx-processor
Add tests to bpvf processor
This commit is contained in:
parent
588cfc56e7
commit
6bc18a968f
2 changed files with 64 additions and 11 deletions
|
@ -8,6 +8,26 @@ from ofxtools.Parser import OFXTree
|
||||||
from ofxtools.header import make_header
|
from ofxtools.header import make_header
|
||||||
|
|
||||||
|
|
||||||
|
def _process_name_and_memo(name, memo):
|
||||||
|
if "CB****" in name:
|
||||||
|
conversion = re.compile(r"\d+,\d{2}[a-zA-Z]{3}")
|
||||||
|
match = conversion.search(memo)
|
||||||
|
if match:
|
||||||
|
res_name = memo[: match.start() - 1]
|
||||||
|
res_memo = name + memo[match.start() - 1 :]
|
||||||
|
else:
|
||||||
|
res_name = memo
|
||||||
|
res_memo = name
|
||||||
|
|
||||||
|
return res_name, res_memo, True
|
||||||
|
|
||||||
|
return name, memo, False
|
||||||
|
|
||||||
|
|
||||||
|
def process_name_and_memo(transaction):
|
||||||
|
return _process_name_and_memo(transaction.name, transaction.memo)
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.argument("ofx_filename")
|
@click.argument("ofx_filename")
|
||||||
def cli(ofx_filename):
|
def cli(ofx_filename):
|
||||||
|
@ -25,18 +45,9 @@ def cli(ofx_filename):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
for transaction in ofx.statements[0].transactions:
|
for transaction in ofx.statements[0].transactions:
|
||||||
if "CB****" in transaction.name:
|
transaction.name, transaction.memo, edited = process_name_and_memo(transaction)
|
||||||
name = transaction.name
|
|
||||||
memo = transaction.memo
|
|
||||||
conversion = re.compile(r"\d+,\d{2}[a-zA-Z]{3}")
|
|
||||||
match = conversion.search(memo)
|
|
||||||
if match:
|
|
||||||
transaction.name = memo[: match.start() - 1]
|
|
||||||
transaction.memo = name + memo[match.start() - 1 :]
|
|
||||||
else:
|
|
||||||
transaction.name = memo
|
|
||||||
transaction.memo = name
|
|
||||||
|
|
||||||
|
if edited:
|
||||||
click.secho(
|
click.secho(
|
||||||
"Edited transaction {} ({})".format(
|
"Edited transaction {} ({})".format(
|
||||||
transaction.checknum, transaction.name
|
transaction.checknum, transaction.name
|
||||||
|
|
42
tests/test_bpvf_processor.py
Normal file
42
tests/test_bpvf_processor.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from ofx_processor.bpvf_processor.main import _process_name_and_memo
|
||||||
|
|
||||||
|
|
||||||
|
class MyTestCase(unittest.TestCase):
|
||||||
|
def test_process_name_and_memo_no_change(self):
|
||||||
|
name = "business"
|
||||||
|
memo = "2020-01-17"
|
||||||
|
|
||||||
|
result_name, result_memo, edited = _process_name_and_memo(name, memo)
|
||||||
|
self.assertFalse(edited)
|
||||||
|
self.assertEqual(result_name, name)
|
||||||
|
self.assertEqual(result_memo, memo)
|
||||||
|
|
||||||
|
def test_process_name_and_memo_change_required_with_conversion(self):
|
||||||
|
name = "150120 CB****5874"
|
||||||
|
memo = "GUY AND SONS FR LYON 0,90EUR 1 EURO = 1,000000"
|
||||||
|
|
||||||
|
expected_name = "GUY AND SONS FR LYON"
|
||||||
|
expected_memo = "150120 CB****5874 0,90EUR 1 EURO = 1,000000"
|
||||||
|
|
||||||
|
result_name, result_memo, edited = _process_name_and_memo(name, memo)
|
||||||
|
self.assertTrue(edited)
|
||||||
|
self.assertEqual(result_name, expected_name)
|
||||||
|
self.assertEqual(result_memo, expected_memo)
|
||||||
|
|
||||||
|
def test_process_name_and_memo_change_required_no_conversion(self):
|
||||||
|
name = "150120 CB****5874"
|
||||||
|
memo = "Dott 75PARIS"
|
||||||
|
|
||||||
|
expected_name = "Dott 75PARIS"
|
||||||
|
expected_memo = "150120 CB****5874"
|
||||||
|
|
||||||
|
result_name, result_memo, edited = _process_name_and_memo(name, memo)
|
||||||
|
self.assertTrue(edited)
|
||||||
|
self.assertEqual(result_name, expected_name)
|
||||||
|
self.assertEqual(result_memo, expected_memo)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Reference in a new issue