diff --git a/monopoly/bank.py b/monopoly/bank.py index d3e04184..08c865c0 100644 --- a/monopoly/bank.py +++ b/monopoly/bank.py @@ -7,7 +7,7 @@ from pandas import DataFrame from monopoly.config import settings -from monopoly.helpers.constants import AMOUNT, DATE, ROOT_DIR +from monopoly.helpers.constants import ROOT_DIR, BankStatement from monopoly.helpers.generate_name import generate_name from monopoly.pdf import PdfConfig, PdfParser from monopoly.statement import Statement, StatementConfig @@ -20,7 +20,6 @@ class Bank: pdf_config: PdfConfig statement_config: StatementConfig file_path: str - date_parser: callable = None transform_dates: bool = True def extract(self) -> Statement: @@ -41,7 +40,9 @@ def transform(self, statement: Statement) -> DataFrame: df = statement.df statement_date = statement.statement_date - df[AMOUNT] = df[AMOUNT].str.replace(",", "").astype(float) + df[BankStatement.AMOUNT] = ( + df[BankStatement.AMOUNT].str.replace(",", "").astype(float) + ) if self.transform_dates: df = self._transform_date_to_iso(df, statement_date) @@ -52,7 +53,9 @@ def _transform_date_to_iso( self, df: DataFrame, statement_date: datetime ) -> DataFrame: logger.info("Transforming dates to ISO 8601") - df[DATE] = df.apply(self._convert_date, statement_date=statement_date, axis=1) + df[BankStatement.DATE] = df.apply( + self._convert_date, statement_date=statement_date, axis=1 + ) return df def parse_date(self, date_str): @@ -61,7 +64,7 @@ def parse_date(self, date_str): return parsed_date.day, parsed_date.month def _convert_date(self, row, statement_date: datetime): - row_day, row_month = self.parse_date(row[DATE]) + row_day, row_month = self.parse_date(row[BankStatement.DATE]) # Deal with mixed years from Jan/Dec if statement_date.month == 1 and row_month == 12: @@ -71,23 +74,21 @@ def _convert_date(self, row, statement_date: datetime): return f"{row_year}-{row_month:02d}-{row_day:02d}" - def _write_to_csv(self, df: DataFrame, statement_date: datetime): - filename = generate_name("file", self.statement_config, statement_date) - - file_path = os.path.join(ROOT_DIR, "output", filename) - logger.info("Writing CSV to file path: %s", file_path) - df.to_csv(file_path, index=False) - - return file_path - def load( self, - transformed_df: DataFrame, + df: DataFrame, statement: Statement, + csv_file_path: str = None, upload_to_cloud: bool = False, ): statement_date = statement.statement_date - csv_file_path = self._write_to_csv(transformed_df, statement_date) + + if not csv_file_path: + filename = generate_name("file", self.statement_config, statement_date) + csv_file_path = os.path.join(ROOT_DIR, "output", filename) + logger.info("Writing CSV to file path: %s", csv_file_path) + + df.to_csv(csv_file_path, index=False) if upload_to_cloud: blob_name = generate_name("blob", self.statement_config, statement_date) diff --git a/monopoly/banks/citibank.py b/monopoly/banks/citibank.py index c738fd08..7a80e62f 100644 --- a/monopoly/banks/citibank.py +++ b/monopoly/banks/citibank.py @@ -2,6 +2,7 @@ from monopoly.bank import BankBase, StatementConfig from monopoly.config import settings +from monopoly.helpers.constants import AccountType, BankNames from monopoly.pdf import PdfConfig logger = logging.getLogger(__name__) @@ -9,8 +10,8 @@ class Citibank(BankBase): statement_config = StatementConfig( - bank_name="Citibank", - account_type="Credit", + bank_name=BankNames.CITIBANK, + account_type=AccountType.CREDIT, transaction_pattern=( r"(?P\b\d{2}\s\w{3}\b)\s*(?P.*?)\s*(?P[\d.,]+)$" ), diff --git a/monopoly/banks/hsbc.py b/monopoly/banks/hsbc.py index 0027b647..39f75e68 100644 --- a/monopoly/banks/hsbc.py +++ b/monopoly/banks/hsbc.py @@ -2,6 +2,7 @@ from monopoly.bank import BankBase, StatementConfig from monopoly.config import settings +from monopoly.helpers.constants import AccountType, BankNames from monopoly.pdf import PdfConfig logger = logging.getLogger(__name__) @@ -9,8 +10,8 @@ class Hsbc(BankBase): statement_config = StatementConfig( - bank_name="HSBC", - account_type="Credit", + bank_name=BankNames.HSBC, + account_type=AccountType.CREDIT, transaction_pattern=( r"\d{2}\s\w{3}\s*" r"(?P\d{2}\s\w{3})\s.*?" diff --git a/monopoly/banks/ocbc.py b/monopoly/banks/ocbc.py index 2a11f74a..36d2d13c 100644 --- a/monopoly/banks/ocbc.py +++ b/monopoly/banks/ocbc.py @@ -2,6 +2,7 @@ from monopoly.bank import BankBase, StatementConfig from monopoly.config import settings +from monopoly.helpers.constants import AccountType, BankNames from monopoly.pdf import PdfConfig logger = logging.getLogger(__name__) @@ -9,8 +10,8 @@ class Ocbc(BankBase): statement_config = StatementConfig( - bank_name="OCBC", - account_type="Credit", + bank_name=BankNames.OCBC, + account_type=AccountType.CREDIT, transaction_pattern=( r"(?P\d+/\d+)\s*(?P.*?)\s*(?P[\d.,]+)$" ), diff --git a/monopoly/helpers/constants.py b/monopoly/helpers/constants.py index 96bbe74c..b5186c56 100644 --- a/monopoly/helpers/constants.py +++ b/monopoly/helpers/constants.py @@ -1,10 +1,25 @@ import os +from enum import Enum -from monopoly.helpers.enums import BankStatement, EmailSubjectRegex - -DATE = BankStatement.DATE.value -DESCRIPTION = BankStatement.DESCRIPTION.value -AMOUNT = BankStatement.AMOUNT.value ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -OCBC = EmailSubjectRegex.OCBC.value -HSBC = EmailSubjectRegex.HSBC.value + + +class AccountType(Enum): + CREDIT = "credit" + + +class BankNames(Enum): + CITIBANK = "citibank" + HSBC = "hsbc" + OCBC = "ocbc" + + +class BankStatement(str, Enum): + DATE = "date" + DESCRIPTION = "description" + AMOUNT = "amount" + + +class EmailSubjectRegex(str, Enum): + OCBC = r"OCBC Bank: Your Credit Card e-Statement" + HSBC = r"Your.HSBC.*eStatement" diff --git a/monopoly/helpers/enums.py b/monopoly/helpers/enums.py deleted file mode 100644 index 76abdfce..00000000 --- a/monopoly/helpers/enums.py +++ /dev/null @@ -1,12 +0,0 @@ -from enum import Enum - - -class BankStatement(str, Enum): - DATE = "date" - DESCRIPTION = "description" - AMOUNT = "amount" - - -class EmailSubjectRegex(str, Enum): - OCBC = r"OCBC Bank: Your Credit Card e-Statement" - HSBC = r"Your.HSBC.*eStatement" diff --git a/monopoly/main.py b/monopoly/main.py index e9c9931a..9beb5539 100644 --- a/monopoly/main.py +++ b/monopoly/main.py @@ -5,7 +5,7 @@ from monopoly.banks.hsbc import Hsbc from monopoly.banks.ocbc import Ocbc from monopoly.gmail import Gmail, Message -from monopoly.helpers.constants import HSBC, OCBC +from monopoly.helpers.constants import EmailSubjectRegex logger = logging.getLogger(__name__) @@ -19,7 +19,7 @@ def main(): messages: list[Message] = Gmail().get_emails() - banks = {OCBC: Ocbc, HSBC: Hsbc} + banks = {EmailSubjectRegex.OCBC: Ocbc, EmailSubjectRegex.HSBC: Hsbc} for message in messages: process_bank_statement(message, banks) diff --git a/monopoly/statement.py b/monopoly/statement.py index e53efd04..4a701f99 100644 --- a/monopoly/statement.py +++ b/monopoly/statement.py @@ -6,7 +6,7 @@ from pandas import DataFrame -from monopoly.helpers.constants import AMOUNT, DATE, DESCRIPTION +from monopoly.helpers.constants import AccountType, BankNames, BankStatement from monopoly.pdf import PdfPage logger = logging.getLogger(__name__) @@ -14,19 +14,31 @@ @dataclass class StatementConfig: - bank_name: str - account_type: str + bank_name: BankNames + account_type: AccountType statement_date_format: str transaction_pattern: str transaction_date_format: str date_pattern: str multiline_transactions: bool = False + # Convert enums to strings + def __post_init__(self): + self.bank_name = self.bank_name.value + self.account_type = self.account_type.value + + +@dataclass +class Transaction: + date: str + description: str + amount: float + @dataclass class Statement: pages: list[PdfPage] - columns = [DATE, DESCRIPTION, AMOUNT] + columns = [enum.value for enum in BankStatement] config: StatementConfig @cached_property @@ -34,10 +46,11 @@ def transactions(self) -> list[dict]: transactions = [] for page in self.pages: for i, line in enumerate(page.lines): - item = self._process_line(line, page.lines, idx=i) - transactions.append(item) + transaction = self._process_line(line, page.lines, idx=i) + if transaction: + transactions.append(transaction) - return list(filter(None, transactions)) + return transactions def _process_line(self, line: str, page: list[str], idx: int) -> dict: if match := re.findall(self.config.transaction_pattern, line): @@ -50,7 +63,7 @@ def _process_line(self, line: str, page: list[str], idx: int) -> dict: except IndexError as err: logger.debug(err) - return {DATE: date, DESCRIPTION: description, AMOUNT: amount} + return vars(Transaction(date, description, amount)) return None @cached_property diff --git a/tests/citibank/test_citibank_extract.py b/tests/citibank/test_citibank_extract.py index 811fe752..1fba93eb 100644 --- a/tests/citibank/test_citibank_extract.py +++ b/tests/citibank/test_citibank_extract.py @@ -2,6 +2,7 @@ from pandas.testing import assert_frame_equal from monopoly.banks.citibank import Citibank +from monopoly.helpers.constants import BankStatement def test_citibank_extract_unprotected_pdf(citibank: Citibank): @@ -9,7 +10,7 @@ def test_citibank_extract_unprotected_pdf(citibank: Citibank): expected_df = pd.read_csv("tests/fixtures/citibank/expected.csv", dtype=object) assert_frame_equal(raw_df, expected_df) - raw_df["amount"] = raw_df["amount"].astype("float") + raw_df[BankStatement.AMOUNT] = raw_df[BankStatement.AMOUNT].astype("float") # total excluding $20 cashback - assert round(raw_df["amount"].sum(), 2) == 1434.07 + assert round(raw_df[BankStatement.AMOUNT].sum(), 2) == 1434.07 diff --git a/tests/citibank/test_citibank_transform.py b/tests/citibank/test_citibank_transform.py index 129a373c..bd529da9 100644 --- a/tests/citibank/test_citibank_transform.py +++ b/tests/citibank/test_citibank_transform.py @@ -5,22 +5,14 @@ from monopoly.bank import Statement from monopoly.banks.citibank import Citibank -from monopoly.helpers.constants import AMOUNT, DATE, DESCRIPTION +from monopoly.statement import Transaction def test_citibank_transform_cross_year(citibank: Citibank, statement: Statement): raw_df = pd.DataFrame( [ - { - DATE: "09 JAN", - DESCRIPTION: "Shopee Singapore SINGAPORE SG", - AMOUNT: "31.45", - }, - { - DATE: "12 DEC", - DESCRIPTION: "UNIQLO SINGAPORE PTE. SINGAPORE SG", - AMOUNT: "29.80", - }, + Transaction("09 JAN", "Shopee Singapore", "31.45"), + Transaction("12 DEC", "UNIQLO SINGAPORE", "29.80"), ] ) statement.statement_date = datetime(2024, 1, 1) @@ -29,16 +21,8 @@ def test_citibank_transform_cross_year(citibank: Citibank, statement: Statement) expected_data = pd.DataFrame( [ - { - DATE: "2024-01-09", - DESCRIPTION: "Shopee Singapore SINGAPORE SG", - AMOUNT: 31.45, - }, - { - DATE: "2023-12-12", - DESCRIPTION: "UNIQLO SINGAPORE PTE. SINGAPORE SG", - AMOUNT: 29.80, - }, + Transaction("2024-01-09", "Shopee Singapore", 31.45), + Transaction("2023-12-12", "UNIQLO SINGAPORE", 29.80), ] ) @@ -48,16 +32,8 @@ def test_citibank_transform_cross_year(citibank: Citibank, statement: Statement) def test_citibank_transform_within_year(citibank: Citibank, statement: Statement): raw_df = pd.DataFrame( [ - { - DATE: "09 JUN", - DESCRIPTION: "Shopee Singapore SINGAPORE SG", - AMOUNT: "31.45", - }, - { - DATE: "12 JUN", - DESCRIPTION: "UNIQLO SINGAPORE PTE. SINGAPORE SG", - AMOUNT: "29.80", - }, + Transaction("09 JUN", "Shopee Singapore", "31.45"), + Transaction("12 JUN", "UNIQLO SINGAPORE", "29.80"), ] ) @@ -68,16 +44,8 @@ def test_citibank_transform_within_year(citibank: Citibank, statement: Statement expected_data = pd.DataFrame( [ - { - DATE: "2023-06-09", - DESCRIPTION: "Shopee Singapore SINGAPORE SG", - AMOUNT: 31.45, - }, - { - DATE: "2023-06-12", - DESCRIPTION: "UNIQLO SINGAPORE PTE. SINGAPORE SG", - AMOUNT: 29.80, - }, + Transaction("2023-06-09", "Shopee Singapore", 31.45), + Transaction("2023-06-12", "UNIQLO SINGAPORE", 29.80), ] ) diff --git a/tests/conftest.py b/tests/conftest.py index e5206a28..258488f8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,7 @@ from monopoly.banks.hsbc import Hsbc from monopoly.banks.ocbc import Ocbc from monopoly.gmail import Message, MessageAttachment +from monopoly.helpers.constants import AccountType, BankNames from monopoly.pdf import PdfConfig, PdfParser @@ -67,8 +68,8 @@ def statement(monkeypatch, statement_config): @pytest.fixture(scope="session") def statement_config(): statement_config = StatementConfig( - account_type="Savings", - bank_name="Example Bank", + account_type=AccountType.CREDIT, + bank_name=BankNames.OCBC, statement_date_format=None, transaction_pattern=None, transaction_date_format=None, diff --git a/tests/gmail/test_main_entrypoint.py b/tests/gmail/test_main_entrypoint.py index bc8ecad7..31245cb5 100644 --- a/tests/gmail/test_main_entrypoint.py +++ b/tests/gmail/test_main_entrypoint.py @@ -2,7 +2,7 @@ import pytest -from monopoly.helpers.constants import HSBC, OCBC +from monopoly.helpers.constants import EmailSubjectRegex from monopoly.main import process_bank_statement @@ -26,9 +26,9 @@ def run_bank_statement_test(message, pattern, subject, expected_result): @pytest.mark.parametrize( "subject,pattern,expected_result", [ - ("OCBC Bank: Your Credit Card e-Statement", OCBC, "call"), - ("Your HSBC VISA REVOLUTION eStatement", HSBC, "call"), - ("Random Subject", OCBC, "ignore"), + ("OCBC Bank: Your Credit Card e-Statement", EmailSubjectRegex.OCBC, "call"), + ("Your HSBC VISA REVOLUTION eStatement", EmailSubjectRegex.HSBC, "call"), + ("Random Subject", EmailSubjectRegex.OCBC, "ignore"), ], ) def test_process_bank_statements( diff --git a/tests/hsbc/test_hsbc_extract.py b/tests/hsbc/test_hsbc_extract.py index 4b253e69..bf33f131 100644 --- a/tests/hsbc/test_hsbc_extract.py +++ b/tests/hsbc/test_hsbc_extract.py @@ -2,6 +2,7 @@ from pandas.testing import assert_frame_equal from monopoly.banks.hsbc import Hsbc +from monopoly.helpers.constants import BankStatement def test_hsbc_extract_unprotected_pdf(hsbc: Hsbc): @@ -9,6 +10,6 @@ def test_hsbc_extract_unprotected_pdf(hsbc: Hsbc): expected_df = pd.read_csv("tests/fixtures/hsbc/expected.csv", dtype=object) assert_frame_equal(raw_df, expected_df) - raw_df["amount"] = raw_df["amount"].astype("float") + raw_df[BankStatement.AMOUNT] = raw_df[BankStatement.AMOUNT].astype("float") - assert round(raw_df["amount"].sum(), 2) == 1218.2 + assert round(raw_df[BankStatement.AMOUNT].sum(), 2) == 1218.2 diff --git a/tests/hsbc/test_hsbc_transform.py b/tests/hsbc/test_hsbc_transform.py index 0ef648cd..6b0bab6e 100644 --- a/tests/hsbc/test_hsbc_transform.py +++ b/tests/hsbc/test_hsbc_transform.py @@ -5,22 +5,14 @@ from monopoly.bank import Statement from monopoly.banks.hsbc import Hsbc -from monopoly.helpers.constants import AMOUNT, DATE, DESCRIPTION +from monopoly.statement import Transaction def test_hsbc_transform_cross_year(hsbc: Hsbc, statement: Statement): raw_df = pd.DataFrame( [ - { - DATE: "09 Jan", - DESCRIPTION: "Shopee Singapore SINGAPORE SG", - AMOUNT: "31.45", - }, - { - DATE: "12 Dec", - DESCRIPTION: "UNIQLO SINGAPORE PTE. SINGAPORE SG", - AMOUNT: "29.80", - }, + Transaction("09 Jan", "Shopee Singapore", "31.45"), + Transaction("12 Dec", "UNIQLO SINGAPORE", "29.80"), ] ) statement.statement_date = datetime(2024, 1, 1) @@ -29,16 +21,8 @@ def test_hsbc_transform_cross_year(hsbc: Hsbc, statement: Statement): expected_data = pd.DataFrame( [ - { - DATE: "2024-01-09", - DESCRIPTION: "Shopee Singapore SINGAPORE SG", - AMOUNT: 31.45, - }, - { - DATE: "2023-12-12", - DESCRIPTION: "UNIQLO SINGAPORE PTE. SINGAPORE SG", - AMOUNT: 29.80, - }, + Transaction("2024-01-09", "Shopee Singapore", 31.45), + Transaction("2023-12-12", "UNIQLO SINGAPORE", 29.80), ] ) @@ -48,16 +32,8 @@ def test_hsbc_transform_cross_year(hsbc: Hsbc, statement: Statement): def test_hsbc_transform_within_year(hsbc: Hsbc, statement: Statement): raw_df = pd.DataFrame( [ - { - DATE: "09 Jun", - DESCRIPTION: "Shopee Singapore SINGAPORE SG", - AMOUNT: "31.45", - }, - { - DATE: "12 Jun", - DESCRIPTION: "UNIQLO SINGAPORE PTE. SINGAPORE SG", - AMOUNT: "29.80", - }, + Transaction("09 Jun", "Shopee Singapore", "31.45"), + Transaction("12 Jun", "UNIQLO SINGAPORE", "29.80"), ] ) @@ -68,16 +44,8 @@ def test_hsbc_transform_within_year(hsbc: Hsbc, statement: Statement): expected_data = pd.DataFrame( [ - { - DATE: "2023-06-09", - DESCRIPTION: "Shopee Singapore SINGAPORE SG", - AMOUNT: 31.45, - }, - { - DATE: "2023-06-12", - DESCRIPTION: "UNIQLO SINGAPORE PTE. SINGAPORE SG", - AMOUNT: 29.80, - }, + Transaction("2023-06-09", "Shopee Singapore", 31.45), + Transaction("2023-06-12", "UNIQLO SINGAPORE", 29.80), ] ) diff --git a/tests/ocbc/test_ocbc_extract.py b/tests/ocbc/test_ocbc_extract.py index 3292fc75..41e7519f 100644 --- a/tests/ocbc/test_ocbc_extract.py +++ b/tests/ocbc/test_ocbc_extract.py @@ -2,6 +2,7 @@ from pandas.testing import assert_frame_equal from monopoly.banks.ocbc import Ocbc +from monopoly.helpers.constants import BankStatement def test_ocbc_extract_unprotected_pdf(ocbc: Ocbc): @@ -10,7 +11,7 @@ def test_ocbc_extract_unprotected_pdf(ocbc: Ocbc): expected_df = pd.read_csv("tests/fixtures/ocbc/expected.csv", dtype=object) assert_frame_equal(raw_df, expected_df) - raw_df["amount"] = raw_df["amount"].astype("float") + raw_df[BankStatement.AMOUNT] = raw_df[BankStatement.AMOUNT].astype("float") # check total (excluding cash rebate) - assert round(raw_df["amount"].sum(), 2) == 703.48 + assert round(raw_df[BankStatement.AMOUNT].sum(), 2) == 703.48 diff --git a/tests/ocbc/test_ocbc_load.py b/tests/ocbc/test_ocbc_load.py index d278f6b4..ccfb2fe9 100644 --- a/tests/ocbc/test_ocbc_load.py +++ b/tests/ocbc/test_ocbc_load.py @@ -1,4 +1,5 @@ import os +import tempfile from datetime import datetime import pandas as pd @@ -6,26 +7,21 @@ from monopoly.bank import Statement from monopoly.banks.ocbc import Ocbc -from monopoly.helpers.constants import AMOUNT, DATE, DESCRIPTION, ROOT_DIR +from monopoly.helpers.constants import ROOT_DIR +from monopoly.statement import Transaction def test_ocbc_write_to_local_csv(ocbc: Ocbc, statement: Statement): transformed_df = pd.DataFrame( [ - { - DATE: "2024-01-12", - DESCRIPTION: "FAIRPRICE FINEST SINGAPORE SG", - AMOUNT: 18.49, - }, - { - DATE: "2023-12-28", - DESCRIPTION: "DA PAOLO GASTRONOMIA SING — SINGAPORE SG", - AMOUNT: 19.69, - }, + Transaction("2024-01-12", "FAIRPRICE FINEST", 18.49), + Transaction("2023-12-28", "DA PAOLO GASTRONOMIA", 19.69), ] ) - statement.statement_date = datetime(2024, 1, 1) - ocbc.load(transformed_df, statement) + statement.statement_date = datetime(2999, 1, 1) + with tempfile.NamedTemporaryFile(delete=True) as temp_file: + csv_file_path = temp_file.name + ocbc.load(df=transformed_df, statement=statement, csv_file_path=csv_file_path) - local_df = pd.read_csv(os.path.join(ROOT_DIR, "output", "OCBC-Credit-2024-01.csv")) - assert_frame_equal(transformed_df, local_df) + local_df = pd.read_csv(os.path.join(csv_file_path)) + assert_frame_equal(transformed_df, local_df) diff --git a/tests/ocbc/test_ocbc_transform.py b/tests/ocbc/test_ocbc_transform.py index 5cb83be0..6bb7e502 100644 --- a/tests/ocbc/test_ocbc_transform.py +++ b/tests/ocbc/test_ocbc_transform.py @@ -5,22 +5,14 @@ from monopoly.bank import Statement from monopoly.banks.ocbc import Ocbc -from monopoly.helpers.constants import AMOUNT, DATE, DESCRIPTION +from monopoly.statement import Transaction def test_ocbc_transform_cross_year(ocbc: Ocbc, statement: Statement): raw_df = pd.DataFrame( [ - { - DATE: "12/01", - DESCRIPTION: "FAIRPRICE FINEST SINGAPORE SG", - AMOUNT: "18.49", - }, - { - DATE: "28/12", - DESCRIPTION: "DA PAOLO GASTRONOMIA SING — SINGAPORE SG", - AMOUNT: "19.69", - }, + Transaction("12/01", "FAIRPRICE FINEST", "18.49"), + Transaction("28/12", "DA PAOLO GASTRONOMIA", "19.69"), ] ) statement.statement_date = datetime(2024, 1, 1) @@ -29,16 +21,8 @@ def test_ocbc_transform_cross_year(ocbc: Ocbc, statement: Statement): expected_data = pd.DataFrame( [ - { - DATE: "2024-01-12", - DESCRIPTION: "FAIRPRICE FINEST SINGAPORE SG", - AMOUNT: 18.49, - }, - { - DATE: "2023-12-28", - DESCRIPTION: "DA PAOLO GASTRONOMIA SING — SINGAPORE SG", - AMOUNT: 19.69, - }, + Transaction("2024-01-12", "FAIRPRICE FINEST", 18.49), + Transaction("2023-12-28", "DA PAOLO GASTRONOMIA", 19.69), ] ) @@ -48,16 +32,8 @@ def test_ocbc_transform_cross_year(ocbc: Ocbc, statement: Statement): def test_ocbc_transform_within_year(ocbc: Ocbc, statement: Statement): raw_df = pd.DataFrame( [ - { - DATE: "12/06", - DESCRIPTION: "FAIRPRICE FINEST SINGAPORE SG", - AMOUNT: "18.49", - }, - { - DATE: "12/06", - DESCRIPTION: "DA PAOLO GASTRONOMIA SING — SINGAPORE SG", - AMOUNT: "19.69", - }, + Transaction("12/06", "FAIRPRICE FINEST", "18.49"), + Transaction("12/06", "DA PAOLO GASTRONOMIA", "19.69"), ] ) statement.statement_date = datetime(2023, 7, 1) @@ -67,16 +43,8 @@ def test_ocbc_transform_within_year(ocbc: Ocbc, statement: Statement): expected_data = pd.DataFrame( [ - { - DATE: "2023-06-12", - DESCRIPTION: "FAIRPRICE FINEST SINGAPORE SG", - AMOUNT: 18.49, - }, - { - DATE: "2023-06-12", - DESCRIPTION: "DA PAOLO GASTRONOMIA SING — SINGAPORE SG", - AMOUNT: 19.69, - }, + Transaction("2023-06-12", "FAIRPRICE FINEST", 18.49), + Transaction("2023-06-12", "DA PAOLO GASTRONOMIA", 19.69), ] ) diff --git a/tests/test_generate_name.py b/tests/test_generate_name.py index 9529a408..7fc9c803 100644 --- a/tests/test_generate_name.py +++ b/tests/test_generate_name.py @@ -14,11 +14,11 @@ def test_generate_blob_name(bank: Bank): statement_date = datetime(2023, 8, 1) expected_blob_name = ( - "bank_name=Example Bank/" - "account_type=Savings/" + "bank_name=ocbc/" + "account_type=credit/" "year=2023/" "month=8/" - "Example Bank-Savings-2023-08-12345foo.csv" + "ocbc-credit-2023-08-12345foo.csv" ) actual_blob_name = generate_name("blob", bank.statement_config, statement_date) @@ -27,7 +27,7 @@ def test_generate_blob_name(bank: Bank): def test_generate_file_name(bank: Bank): statement_date = datetime(2023, 8, 1) - expected_file_name = "Example Bank-Savings-2023-08.csv" + expected_file_name = "ocbc-credit-2023-08.csv" actual_file_name = generate_name("file", bank.statement_config, statement_date)