2020-01-17 16:18:47 +01:00
|
|
|
import datetime
|
2020-02-26 19:59:31 +01:00
|
|
|
import json
|
2020-01-17 16:18:47 +01:00
|
|
|
import unittest
|
|
|
|
|
2020-02-23 09:23:42 +01:00
|
|
|
from ofx_processor.processors.revolut import (
|
2020-02-22 14:53:52 +01:00
|
|
|
_amount_str_to_float,
|
2020-02-22 15:25:51 +01:00
|
|
|
RevolutLine,
|
2020-02-26 19:59:31 +01:00
|
|
|
RevolutProcessor,
|
2020-01-17 16:18:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-02-26 20:08:43 +01:00
|
|
|
class RevolutLineTestCase(unittest.TestCase):
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_convert_amount_with_one_decimal_place(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
amount = "3,4"
|
|
|
|
expected = 3.4
|
2020-02-22 14:53:52 +01:00
|
|
|
self.assertEqual(_amount_str_to_float(amount), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_convert_amount_with_two_decimal_places(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
amount = "3,41"
|
|
|
|
expected = 3.41
|
2020-02-22 14:53:52 +01:00
|
|
|
self.assertEqual(_amount_str_to_float(amount), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_convert_amount_with_empty_string(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
amount = ""
|
|
|
|
expected = ""
|
2020-02-22 14:53:52 +01:00
|
|
|
self.assertEqual(_amount_str_to_float(amount), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_get_memo_with_category_and_rate(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
line = {"Category": "category name", "Exchange Rate": "exchange rate"}
|
|
|
|
expected = "category name - exchange rate"
|
2020-02-22 15:25:51 +01:00
|
|
|
self.assertEqual(RevolutLine(line).get_memo(), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_get_memo_with_only_category(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
line = {"Category": "category name", "Exchange Rate": ""}
|
|
|
|
expected = "category name"
|
2020-02-22 15:25:51 +01:00
|
|
|
self.assertEqual(RevolutLine(line).get_memo(), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_get_memo_with_only_rate(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
line = {"Category": "", "Exchange Rate": "exchange rate"}
|
|
|
|
expected = "exchange rate"
|
2020-02-22 15:25:51 +01:00
|
|
|
self.assertEqual(RevolutLine(line).get_memo(), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_get_memo_with_missing_keys(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
line = {"Category": "category name"}
|
|
|
|
expected = "category name"
|
2020-02-22 15:25:51 +01:00
|
|
|
self.assertEqual(RevolutLine(line).get_memo(), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_get_date(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
line = {"Completed Date": "January 16"}
|
|
|
|
current_year = datetime.date.today().year
|
|
|
|
expected = f"{current_year}-01-16"
|
2020-02-22 15:25:51 +01:00
|
|
|
self.assertEqual(RevolutLine(line).get_date(), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_get_date_other_year(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
line = {"Completed Date": "January 16 2019"}
|
|
|
|
expected = f"2019-01-16"
|
2020-02-22 15:25:51 +01:00
|
|
|
self.assertEqual(RevolutLine(line).get_date(), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_get_amount_inflow(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
line = {"Paid In (EUR)": "3,42"}
|
2020-02-26 18:32:31 +01:00
|
|
|
expected = 3420
|
|
|
|
self.assertEqual(RevolutLine(line).get_amount(), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
2020-02-26 18:32:31 +01:00
|
|
|
def test_get_amount_outflow(self):
|
2020-01-17 16:18:47 +01:00
|
|
|
line = {"Paid Out (EUR)": "8,42"}
|
2020-02-26 18:32:31 +01:00
|
|
|
expected = -8420
|
|
|
|
self.assertEqual(RevolutLine(line).get_amount(), expected)
|
|
|
|
|
|
|
|
def test_get_payee(self):
|
|
|
|
line = {"Reference": "Hello world"}
|
|
|
|
expected = line["Reference"]
|
|
|
|
self.assertEqual(RevolutLine(line).get_payee(), expected)
|
2020-01-17 16:18:47 +01:00
|
|
|
|
|
|
|
|
2020-02-26 20:07:15 +01:00
|
|
|
class RevolutProcessorTestCase(unittest.TestCase):
|
2020-02-26 19:59:31 +01:00
|
|
|
def test_file_not_found(self):
|
|
|
|
with self.assertRaises(SystemExit):
|
|
|
|
RevolutProcessor("notfound.csv").get_transactions()
|
|
|
|
|
|
|
|
def test_file(self):
|
|
|
|
transactions = RevolutProcessor("tests/samples/revolut.csv").get_transactions()
|
|
|
|
with open("tests/samples/revolut_expected.json") as f:
|
|
|
|
expected_transactions = json.load(f)
|
|
|
|
|
|
|
|
self.assertListEqual(transactions, expected_transactions)
|
|
|
|
|
|
|
|
|
2020-01-17 16:18:47 +01:00
|
|
|
if __name__ == "__main__":
|
2020-02-26 18:56:49 +01:00
|
|
|
unittest.main() # pragma: nocover
|