2020-02-26 18:56:49 +01:00
|
|
|
import datetime
|
2020-01-17 16:34:26 +01:00
|
|
|
import unittest
|
|
|
|
|
2020-02-26 17:48:21 +01:00
|
|
|
from ofx_processor.processors.bpvf import BpvfLine
|
2020-01-17 16:34:26 +01:00
|
|
|
|
|
|
|
|
2020-02-26 18:56:49 +01:00
|
|
|
class BpvfTransaction:
|
|
|
|
"""
|
|
|
|
Mimick what is retrieved via ofxtools when parsing the file
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
name: str = "",
|
|
|
|
memo: str = "",
|
|
|
|
dtposted: datetime.datetime = None,
|
|
|
|
trnamt: float = 0,
|
|
|
|
):
|
|
|
|
self.dtposted = dtposted
|
|
|
|
self.memo = memo
|
|
|
|
self.trnamt = trnamt
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
|
|
|
|
class BpvfProcessorTestCase(unittest.TestCase):
|
2020-01-17 16:34:26 +01:00
|
|
|
def test_process_name_and_memo_no_change(self):
|
|
|
|
name = "business"
|
|
|
|
memo = "2020-01-17"
|
2020-02-26 18:56:49 +01:00
|
|
|
transaction = BpvfTransaction(name=name, memo=memo)
|
2020-01-17 16:34:26 +01:00
|
|
|
|
2020-02-26 18:56:49 +01:00
|
|
|
line = BpvfLine(transaction)
|
|
|
|
result_name = line.get_payee()
|
|
|
|
result_memo = line.get_memo()
|
2020-01-17 16:34:26 +01:00
|
|
|
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"
|
2020-02-26 18:56:49 +01:00
|
|
|
transaction = BpvfTransaction(name=name, memo=memo)
|
2020-01-17 16:34:26 +01:00
|
|
|
|
|
|
|
expected_name = "GUY AND SONS FR LYON"
|
|
|
|
expected_memo = "150120 CB****5874 0,90EUR 1 EURO = 1,000000"
|
|
|
|
|
2020-02-26 18:56:49 +01:00
|
|
|
line = BpvfLine(transaction)
|
|
|
|
result_name = line.get_payee()
|
|
|
|
result_memo = line.get_memo()
|
2020-01-17 16:34:26 +01:00
|
|
|
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"
|
2020-02-26 18:56:49 +01:00
|
|
|
transaction = BpvfTransaction(name=name, memo=memo)
|
2020-01-17 16:34:26 +01:00
|
|
|
|
|
|
|
expected_name = "Dott 75PARIS"
|
|
|
|
expected_memo = "150120 CB****5874"
|
|
|
|
|
2020-02-26 18:56:49 +01:00
|
|
|
line = BpvfLine(transaction)
|
|
|
|
result_name = line.get_payee()
|
|
|
|
result_memo = line.get_memo()
|
2020-01-17 16:34:26 +01:00
|
|
|
self.assertEqual(result_name, expected_name)
|
|
|
|
self.assertEqual(result_memo, expected_memo)
|
|
|
|
|
2020-02-26 18:56:49 +01:00
|
|
|
def test_get_date(self):
|
|
|
|
transaction = BpvfTransaction(dtposted=datetime.datetime(2020, 1, 23, 1, 2, 3))
|
|
|
|
expected_date = "2020-01-23"
|
|
|
|
|
|
|
|
result_date = BpvfLine(transaction).get_date()
|
|
|
|
self.assertEqual(result_date, expected_date)
|
|
|
|
|
|
|
|
def test_get_amount_positive(self):
|
|
|
|
transaction = BpvfTransaction(trnamt=52.2)
|
|
|
|
expected_amount = 52200
|
|
|
|
|
|
|
|
result_amount = BpvfLine(transaction).get_amount()
|
|
|
|
self.assertEqual(result_amount, expected_amount)
|
|
|
|
|
|
|
|
def test_get_amount_negative(self):
|
|
|
|
transaction = BpvfTransaction(trnamt=-52.2)
|
|
|
|
expected_amount = -52200
|
|
|
|
|
|
|
|
result_amount = BpvfLine(transaction).get_amount()
|
|
|
|
self.assertEqual(result_amount, expected_amount)
|
|
|
|
|
2020-01-17 16:34:26 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-02-26 18:56:49 +01:00
|
|
|
unittest.main() # pragma: nocover
|