diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..91abb11 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/workflows/verify-script.yml b/.github/workflows/verify-script.yml new file mode 100644 index 0000000..4f2f7c6 --- /dev/null +++ b/.github/workflows/verify-script.yml @@ -0,0 +1,28 @@ +name: Verify Script + +on: [push,workflow_dispatch,pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.10", "3.11" ] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Analysing the code with pylint + run: | + pylint --errors-only $(find src/ -name "*.py" | xargs) + - name: Running tests + run: | + python -m unittest diff --git a/README.md b/README.md index 486ccd7..7ca088f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # MoneyMoney Extension: Sum by Bank -This is a Pyton script for the great [MoneyMoney software](https://moneymoney-app.com/) to generate a list with all balances by bank account. +![build status](https://github.com/ma4nn/moneymoney-sum-by-bank/actions/workflows/verify-script.yml/badge.svg) + +This is a Python script for the great [MoneyMoney software](https://moneymoney-app.com/) to generate a list with all balances by bank account. This is useful e.g. to export the total values per bank to a summary Excel document or to monitor certain threshold values per bank. ## Installation diff --git a/moneymoney_api.py b/moneymoney_api.py index 615b977..cfb6019 100644 --- a/moneymoney_api.py +++ b/moneymoney_api.py @@ -13,7 +13,7 @@ class Account(TypedDict): name: str bankCode: str - balance: list[float | str] + balance: list[list[float | str]] portfolio: bool group: bool attributes: dict[str, str] diff --git a/test_moneymoney_sum_by_bank.py b/test_moneymoney_sum_by_bank.py new file mode 100644 index 0000000..3935a46 --- /dev/null +++ b/test_moneymoney_sum_by_bank.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +""" + Unit Tests +""" + +import unittest +import pandas as pd +from pandas.testing import assert_frame_equal +from moneymoney_api import Account +from moneymoney_sum_by_bank import sum_by_account + + +class TestSumByBank(unittest.TestCase): + + def test_empty(self): + df = sum_by_account([]) + + assert df.empty is True + + def test_single_account(self): + accounts: list[Account] = [ + Account(name='Test Bank A', balance=[[1000.00, 'EUR']], portfolio=False, group=False, bankCode='TES1') + ] + + df_expected = pd.DataFrame([{'bank': 'TES1', 'currency': 'EUR', 'balance': 1000.00}]).set_index(['bank', 'currency']) + df = sum_by_account(accounts) + + assert_frame_equal(df_expected, df, check_exact=True) + + def test_single_account_no_bank_code(self): + accounts: list[Account] = [ + Account(name='Test Bank A', balance=[[1000.00, 'EUR']], portfolio=False, group=False, bankCode='', attributes={'bankIdentifier': 'TES1'}) + ] + + df_expected = pd.DataFrame([{'bank': 'TES1', 'currency': 'EUR', 'balance': 1000.00}]).set_index(['bank', 'currency']) + df = sum_by_account(accounts) + + assert_frame_equal(df_expected, df, check_exact=True) + + def test_multi_accounts_same_bank(self): + accounts: list[Account] = [ + Account(name='Test Bank A', balance=[[1000.00, 'EUR']], portfolio=False, group=False, bankCode='TES1'), + Account(name='Test Bank A', balance=[[490.18, 'EUR']], portfolio=False, group=False, bankCode='TES1') + ] + + df_expected = pd.DataFrame([{'bank': 'TES1', 'currency': 'EUR', 'balance': 1490.18}]).set_index(['bank', 'currency']) + df = sum_by_account(accounts) + + assert_frame_equal(df_expected, df, check_exact=True) + + def test_multi_accounts(self): + accounts: list[Account] = [ + Account(name='Test Bank A', balance=[[1000.00, 'EUR']], portfolio=False, group=False, bankCode='TES1'), + Account(name='Test Bank A', balance=[[490.18, 'EUR']], portfolio=False, group=False, bankCode='TES1IGNORED'), + Account(name='Test Bank B', balance=[[0.99, 'EUR']], portfolio=False, group=False, bankCode='TES2'), + Account(name='Test Bank C', balance=[[0, 'EUR']], portfolio=False, group=False, bankCode='TES3'), + Account(name='Test Bank B', balance=[[0.9988, 'EUR']], portfolio=False, group=False, bankCode='TES2') + ] + + df_expected = pd.DataFrame([{'bank': 'TES1', 'currency': 'EUR', 'balance': 1490.18}, {'bank': 'TES2', 'currency': 'EUR', 'balance': 1.9888}, {'bank': 'TES3', 'currency': 'EUR', 'balance': 0}]).set_index(['bank', 'currency']) + df = sum_by_account(accounts) + + assert_frame_equal(df_expected, df, check_exact=True)