Add tests to revolut processor
This commit is contained in:
parent
4963c3e7a7
commit
ee182990f4
3 changed files with 91 additions and 10 deletions
|
@ -13,10 +13,25 @@ def process_amount(amount):
|
||||||
|
|
||||||
def process_memo(line):
|
def process_memo(line):
|
||||||
return " - ".join(
|
return " - ".join(
|
||||||
filter(None, map(str.strip, [line["Category"], line["Exchange Rate"]]))
|
filter(
|
||||||
|
None,
|
||||||
|
map(str.strip, [line.get("Category", ""), line.get("Exchange Rate", "")]),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def process_date(line):
|
||||||
|
return dateparser.parse(line.get("Completed Date")).strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
|
||||||
|
def process_inflow(line):
|
||||||
|
return process_amount(line.get("Paid In (EUR)"))
|
||||||
|
|
||||||
|
|
||||||
|
def process_outflow(line):
|
||||||
|
return process_amount(line.get("Paid Out (EUR)"))
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.argument("csv_filename")
|
@click.argument("csv_filename")
|
||||||
def cli(csv_filename):
|
def cli(csv_filename):
|
||||||
|
@ -25,14 +40,13 @@ def cli(csv_filename):
|
||||||
with open(csv_filename) as f:
|
with open(csv_filename) as f:
|
||||||
reader = csv.DictReader(f, delimiter=";")
|
reader = csv.DictReader(f, delimiter=";")
|
||||||
for line in reader:
|
for line in reader:
|
||||||
date = dateparser.parse(line["Completed Date"])
|
|
||||||
formatted_data.append(
|
formatted_data.append(
|
||||||
{
|
{
|
||||||
"Date": date.strftime("%Y-%m-%d"),
|
"Date": process_date(line),
|
||||||
"Payee": line["Reference"],
|
"Payee": line["Reference"],
|
||||||
"Memo": process_memo(line),
|
"Memo": process_memo(line),
|
||||||
"Outflow": process_amount(line["Paid Out (EUR)"]),
|
"Outflow": process_outflow(line),
|
||||||
"Inflow": process_amount(line["Paid In (EUR)"]),
|
"Inflow": process_inflow(line),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
from ofx_processor.bpvf_processor import __version__
|
|
||||||
|
|
||||||
|
|
||||||
def test_version():
|
|
||||||
assert __version__ == "0.1.3"
|
|
72
tests/test_revolut_processor.py
Normal file
72
tests/test_revolut_processor.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
import datetime
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from ofx_processor.revolut_processor.main import (
|
||||||
|
process_amount,
|
||||||
|
process_memo,
|
||||||
|
process_date,
|
||||||
|
process_inflow,
|
||||||
|
process_outflow,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RevolutProcessorTestCase(unittest.TestCase):
|
||||||
|
def test_process_amount_with_one_decimal_place(self):
|
||||||
|
amount = "3,4"
|
||||||
|
expected = 3.4
|
||||||
|
self.assertEqual(process_amount(amount), expected)
|
||||||
|
|
||||||
|
def test_process_amount_with_two_decimal_places(self):
|
||||||
|
amount = "3,41"
|
||||||
|
expected = 3.41
|
||||||
|
self.assertEqual(process_amount(amount), expected)
|
||||||
|
|
||||||
|
def test_process_amount_with_empty_string(self):
|
||||||
|
amount = ""
|
||||||
|
expected = ""
|
||||||
|
self.assertEqual(process_amount(amount), expected)
|
||||||
|
|
||||||
|
def test_process_memo_with_category_and_rate(self):
|
||||||
|
line = {"Category": "category name", "Exchange Rate": "exchange rate"}
|
||||||
|
expected = "category name - exchange rate"
|
||||||
|
self.assertEqual(process_memo(line), expected)
|
||||||
|
|
||||||
|
def test_process_memo_with_only_category(self):
|
||||||
|
line = {"Category": "category name", "Exchange Rate": ""}
|
||||||
|
expected = "category name"
|
||||||
|
self.assertEqual(process_memo(line), expected)
|
||||||
|
|
||||||
|
def test_process_memo_with_only_rate(self):
|
||||||
|
line = {"Category": "", "Exchange Rate": "exchange rate"}
|
||||||
|
expected = "exchange rate"
|
||||||
|
self.assertEqual(process_memo(line), expected)
|
||||||
|
|
||||||
|
def test_process_memo_with_missing_keys(self):
|
||||||
|
line = {"Category": "category name"}
|
||||||
|
expected = "category name"
|
||||||
|
self.assertEqual(process_memo(line), expected)
|
||||||
|
|
||||||
|
def test_process_date(self):
|
||||||
|
line = {"Completed Date": "January 16"}
|
||||||
|
current_year = datetime.date.today().year
|
||||||
|
expected = f"{current_year}-01-16"
|
||||||
|
self.assertEqual(process_date(line), expected)
|
||||||
|
|
||||||
|
def test_process_date_other_year(self):
|
||||||
|
line = {"Completed Date": "January 16 2019"}
|
||||||
|
expected = f"2019-01-16"
|
||||||
|
self.assertEqual(process_date(line), expected)
|
||||||
|
|
||||||
|
def test_process_inflow(self):
|
||||||
|
line = {"Paid In (EUR)": "3,42"}
|
||||||
|
expected = 3.42
|
||||||
|
self.assertEqual(process_inflow(line), expected)
|
||||||
|
|
||||||
|
def test_process_outflow(self):
|
||||||
|
line = {"Paid Out (EUR)": "8,42"}
|
||||||
|
expected = 8.42
|
||||||
|
self.assertEqual(process_outflow(line), expected)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Reference in a new issue