From eb629a9a4f2d7d0fce970f9b2a528c89323f6afc Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 17 Sep 2021 14:16:16 +0200 Subject: [PATCH] Fix whitespaces in new revolut format --- ofx_processor/processors/revolut.py | 7 +++++-- tests/samples/revolut.csv | 19 ++++++++++--------- tests/samples/revolut_expected.json | 9 ++++++++- tests/samples/revolut_transactions.json | 8 ++++++++ tests/test_end_to_end.py | 17 ++++++++++------- 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/ofx_processor/processors/revolut.py b/ofx_processor/processors/revolut.py index c43ec8d..6cb2de7 100644 --- a/ofx_processor/processors/revolut.py +++ b/ofx_processor/processors/revolut.py @@ -1,4 +1,5 @@ import csv +import re import sys import click @@ -7,9 +8,11 @@ import dateparser from ofx_processor.utils.base_processor import BaseProcessor, BaseLine -def _amount_str_to_float(amount): +def _amount_str_to_float(amount: str): if amount: - return float(amount.replace(",", ".")) + amount = amount.replace(",", ".") + amount = re.sub(r"\s+", "", amount) + return float(amount) return "" diff --git a/tests/samples/revolut.csv b/tests/samples/revolut.csv index 9207757..01ff66a 100644 --- a/tests/samples/revolut.csv +++ b/tests/samples/revolut.csv @@ -1,10 +1,11 @@ Completed Date;Reference;Paid Out (EUR);Paid In (EUR);Exchange Out;Exchange In; Balance (EUR);Exchange Rate;Category -29 Jan;To Person 1;53,63;;;;21,66; ;Transfers -29 Jan;To Person 2;0,90;;;;75,29; ;Transfers -29 Jan;Refund from Company 2;;53,63;;;76,19; ;Shopping -24 Jan;To Person 3;8,50;;;;22,56; ;Transfers -16 Jan;To Person 4;1,40;;;;31,06; ;Transfers -10 Jan;To Person 5;2,01;;;;32,46; ;Transfers -10 Jan;To Person 6;1,21;;;;34,47; ;Transfers -5 Jan;Company 1;123,68;;USD 138,00;;35,68;FX-rate €1 = US$1,1158;Shopping -4 Jan;Top-up via Apple Pay;;100,00;;;159,36; ;General +30 août 2021;Virement de NAME;;1 500,00 ;;;1 521,66 ; ;Transferts +29 Jan 2020;To Person 1;53,63;;;;21,66; ;Transfers +29 Jan 2020;To Person 2;0,90;;;;75,29; ;Transfers +29 Jan 2020;Refund from Company 2;;53,63;;;76,19; ;Shopping +24 Jan 2020;To Person 3;8,50;;;;22,56; ;Transfers +16 Jan 2020;To Person 4;1,40;;;;31,06; ;Transfers +10 Jan 2020;To Person 5;2,01;;;;32,46; ;Transfers +10 Jan 2020;To Person 6;1,21;;;;34,47; ;Transfers +5 Jan 2020;Company 1;123,68;;USD 138,00;;35,68;FX-rate €1 = US$1,1158;Shopping +4 Jan 2020;Top-up via Apple Pay;;100,00;;;159,36; ;General diff --git a/tests/samples/revolut_expected.json b/tests/samples/revolut_expected.json index c5e6709..d8b2e56 100644 --- a/tests/samples/revolut_expected.json +++ b/tests/samples/revolut_expected.json @@ -1,4 +1,11 @@ [ + { + "date": "2021-08-30", + "amount": 1500000, + "payee_name": "Virement de NAME", + "memo": "Transferts", + "import_id": "YNAB:1500000:2021-08-30:1" + }, { "date": "2020-01-29", "amount": -53630, @@ -62,4 +69,4 @@ "memo": "General", "import_id": "YNAB:100000:2020-01-04:1" } -] \ No newline at end of file +] diff --git a/tests/samples/revolut_transactions.json b/tests/samples/revolut_transactions.json index dab48a0..761d800 100644 --- a/tests/samples/revolut_transactions.json +++ b/tests/samples/revolut_transactions.json @@ -1,5 +1,13 @@ { "transactions": [ + { + "date": "2021-08-30", + "amount": 1500000, + "payee_name": "Virement de NAME", + "memo": "Transferts", + "import_id": "YNAB:1500000:2021-08-30:1", + "account_id": "" + }, { "date": "2020-01-29", "amount": -53630, diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index e668796..c61dfef 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -77,7 +77,7 @@ class ConfigTestCase(unittest.TestCase): self.cli, ["revolut", "tests/samples/revolut.csv", "--keep"] ) expected_filename = ynab.get_config_file_name() - self.assertIn("Error while parsing config file", result.output) + self.assertIn("Error while parsing config file", result.output, f"config_file: {name}") edit.assert_called_with(filename=expected_filename) @mock.patch("ofx_processor.utils.ynab.DEFAULT_CONFIG_FILENAME", "file.ini") @@ -187,6 +187,7 @@ class DataTestCase(unittest.TestCase): {"id": "created:9", "matched_transaction_id": None}, {"id": "created:10", "matched_transaction_id": None}, {"id": "created:11", "matched_transaction_id": None}, + {"id": "created:12", "matched_transaction_id": None}, ], "duplicate_import_ids": [], } @@ -198,8 +199,8 @@ class DataTestCase(unittest.TestCase): ) self.assertEqual(result.exit_code, 0) - self.assertIn("Processed 9 transactions total.", result.output) - self.assertIn("9 transactions created in YNAB.", result.output) + self.assertIn("Processed 10 transactions total.", result.output) + self.assertIn("10 transactions created in YNAB.", result.output) self.assertNotIn("transactions ignored (duplicates).", result.output) @mock.patch("requests.post") @@ -232,6 +233,7 @@ class DataTestCase(unittest.TestCase): "duplicate:9", "duplicate:10", "duplicate:11", + "duplicate:12", ], } } @@ -242,9 +244,9 @@ class DataTestCase(unittest.TestCase): ) self.assertEqual(result.exit_code, 0) - self.assertIn("Processed 9 transactions total.", result.output) + self.assertIn("Processed 10 transactions total.", result.output) self.assertIn("3 transactions created in YNAB.", result.output) - self.assertIn("6 transactions ignored (duplicates).", result.output) + self.assertIn("7 transactions ignored (duplicates).", result.output) @mock.patch("requests.post") def test_revolut_sends_data_only_duplicates(self, post): @@ -261,6 +263,7 @@ class DataTestCase(unittest.TestCase): "duplicate:7", "duplicate:8", "duplicate:9", + "duplicate:10", ], } } @@ -271,9 +274,9 @@ class DataTestCase(unittest.TestCase): ) self.assertEqual(result.exit_code, 0) - self.assertIn("Processed 9 transactions total.", result.output) + self.assertIn("Processed 10 transactions total.", result.output) self.assertNotIn("transactions created in YNAB.", result.output) - self.assertIn("9 transactions ignored (duplicates).", result.output) + self.assertIn("10 transactions ignored (duplicates).", result.output) @mock.patch("requests.post") def test_bpvf_sends_to_ynab(self, post):