-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_moneymoney_sum_by_bank.py
63 lines (46 loc) · 2.72 KB
/
test_moneymoney_sum_by_bank.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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)