예제 #1
0
 def test_a_bank(self):
     # Create checking account.
     bank = Bank()
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     cormo_checking = CheckingAccount("101-checking-1",
                                      "checking",
                                      cormo.accounts,
                                      "101",
                                      opening_balance=1000)
     assert cormo.accountholder_id in bank.account_holders
     assert cormo_checking.account_id in cormo.accounts.checking_accounts
     assert isinstance(bank.account_holders[cormo.accountholder_id],
                       AccountHolder)
     assert isinstance(
         bank.account_holders[cormo.accountholder_id].accounts.
         checking_accounts[cormo_checking.account_id],
         CheckingAccount,
     )
     # Bank balance == the only accounts balance.
     assert bank.bank_balance == cormo_checking.balance
     frydy = AccountHolder(bank, "202", "Josh", "Frydenberg")
     frydy_savings = SavingsAccount("202-savings-1",
                                    "savings",
                                    frydy.accounts,
                                    "202",
                                    opening_balance=0.25)
     # Bank balance == total of accounts balances.
     assert bank.bank_balance == cormo_checking.balance + frydy_savings.balance
예제 #2
0
 def test_c_account_withdraw(self):
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     cormo_checking = CheckingAccount("101",
                                      "checking",
                                      cormo.accounts,
                                      "101-checking-1",
                                      opening_balance=1000)
     trans = cormo_checking.withdraw(500.00)
     assert trans["status"]
     assert trans["new_balance"] == 500.00
     assert cormo_checking.balance == 500.00
     # Test insufficient balance withdrawal.
     try:
         trans = cormo_checking.withdraw(700.00)
     except InsufficientBalance as e:
         assert isinstance(e, InsufficientBalance)
     assert cormo_checking.balance == 500.00
     # Test exceeds limit withdrawal.
     try:
         cormo_checking.deposit(7000.00)
         trans = cormo_checking.withdraw(7000.00)
     except ExceedsLimit as e:
         assert isinstance(e, ExceedsLimit)
     # test account status
     cormo_checking.status = "locked"
     try:
         trans = cormo_checking.withdraw(700.00)
     except AccountError as e:
         assert isinstance(e, AccountError)
예제 #3
0
 def test_a_card(self):
     # Create checking account.
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     cormo_checking = CheckingAccount("101",
                                      "checking",
                                      cormo.accounts,
                                      "101-checking-1",
                                      opening_balance=1000)
     assert cormo_checking.account_id in cormo.accounts.checking_accounts
     assert isinstance(
         cormo.accounts.checking_accounts[cormo_checking.account_id],
         CheckingAccount,
     )
     cormo_checking_card = Card(
         cormo,
         cormo_checking,
         "Mathias",
         "Cormann",
         "40001|101-checking-1",
         "0101",
         "12-12-2024",
         "432",
         "active",
     )
     assert (cormo_checking_card.card_number
             in cormo.accounts.checking_accounts[
                 cormo_checking.account_id].linked_cards)
     assert isinstance(
         cormo.accounts.checking_accounts[cormo_checking.account_id].
         linked_cards[cormo_checking_card.card_number],
         Card,
     )
예제 #4
0
 def test_b_more_ahs(self):
     # Create 10K accounts, process withdrawals check balances.
     bank = Bank()
     n = 10000
     for i in range(n):
         ah = AccountHolder(bank, f"{i}1", "Mathias", "Cormann")
         ac = CheckingAccount(
             f"{i}1-checking-1",
             "checking",
             ah.accounts,
             f"{i}1",
             opening_balance=1000.00,
         )
         c = Card(
             ah,
             ac,
             "Mathias",
             "Cormann",
             f"40001|{i}1-checking-1",
             "0101",
             "12-12-2024",
             "432",
             "active",
         )
     print(bank.bank_balance, len(bank.account_holders))
     assert bank.bank_balance == 1000 * n
     for id, acchldr in bank.account_holders.items():
         bank.withdrawal_transaction(f"40001|{id}-checking-1", 500.00)
     assert bank.bank_balance == 500 * n
예제 #5
0
 def test_a_create_ah(self):
     # Create a card holder.
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     assert cormo.accountholder_id == "101"
     assert cormo.first_name == "Mathias"
     assert cormo.last_name == "Cormann"
     assert isinstance(cormo.accounts, Accounts)
     assert cormo.cards == {}
예제 #6
0
 def test_b_ch_account(self):
     # Create a card holder and assign an account.
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     assert cormo.accountholder_id == "101"
     assert cormo.first_name == "Mathias"
     assert cormo.last_name == "Cormann"
     cormo_checking = CheckingAccount(
         "101", "checking", cormo.accounts, "101-checking-1", opening_balance=1000
     )
     assert cormo_checking.account_id in cormo.accounts.checking_accounts
예제 #7
0
 def test_c_account_deposit(self):
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     cormo_checking = CheckingAccount("101",
                                      "checking",
                                      cormo.accounts,
                                      "101-checking-1",
                                      opening_balance=1000)
     trans = cormo_checking.deposit(500.00)
     assert trans["status"]
     assert trans["new_balance"] == 1500.00
     assert cormo_checking.balance == 1500.00
예제 #8
0
 def test_b_create_savings(self):
     # Create saving account.
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     cormo_saving = SavingsAccount("101",
                                   "saving",
                                   cormo.accounts,
                                   "101-saving-1",
                                   opening_balance=1000)
     assert cormo_saving.account_id in cormo.accounts.saving_accounts
     assert isinstance(
         cormo.accounts.saving_accounts[cormo_saving.account_id],
         SavingsAccount)
예제 #9
0
 def test_a_create_checking(self):
     # Create checking account.
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     cormo_checking = CheckingAccount("101",
                                      "checking",
                                      cormo.accounts,
                                      "101-checking-1",
                                      opening_balance=1000)
     assert cormo_checking.account_id in cormo.accounts.checking_accounts
     assert isinstance(
         cormo.accounts.checking_accounts[cormo_checking.account_id],
         CheckingAccount)
예제 #10
0
 def test_d_accounts(self):
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     cormo_checking = CheckingAccount("101",
                                      "checking",
                                      cormo.accounts,
                                      "101-checking-1",
                                      opening_balance=1000.00)
     cormo_savings = SavingsAccount("101",
                                    "savings",
                                    cormo.accounts,
                                    "101-saving-1",
                                    opening_balance=1000.00)
     assert cormo.accounts.total_balance == 2000.00
     assert cormo.accounts._checking_balance == 1000.00
     assert cormo.accounts._savings_balance == 1000.00
     assert cormo.accounts.accounts == "Accounts: Checking: 1, Savings: 1, Credit: 0"
예제 #11
0
 def test_c_ch_account_card(self):
     # Create card hold, account and card.
     cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
     assert cormo.accountholder_id == "101"
     assert cormo.first_name == "Mathias"
     assert cormo.last_name == "Cormann"
     # Create account verify it's in the registered account holders accounts.
     cormo_checking = CheckingAccount(
         "101", "checking", cormo.accounts, "101-checking-1", opening_balance=1000
     )
     assert cormo_checking.account_id in cormo.accounts.checking_accounts
     assert isinstance(
         cormo.accounts.checking_accounts[cormo_checking.account_id],
         CheckingAccount,
     )
     # Create a card, validate we can access card and account info.
     cormo_checking_card = Card(
         cormo,
         cormo_checking,
         "Mathias",
         "Cormann",
         "40001",
         "0101",
         "12-12-2024",
         "432",
         "active",
     )
     assert cormo_checking_card.card_number in cormo.accounts.issued_cards
     assert isinstance(
         cormo.accounts.issued_cards[cormo_checking_card.card_number]["account"],
         CheckingAccount,
     )
     assert isinstance(
         cormo.accounts.issued_cards[cormo_checking_card.card_number]["card"], Card
     )
     assert (
         cormo_checking_card.card_number
         in cormo.accounts.checking_accounts[cormo_checking.account_id].linked_cards
     )
     assert isinstance(
         cormo.accounts.checking_accounts[cormo_checking.account_id].linked_cards[
             cormo_checking_card.card_number
         ],
         Card,
     )
예제 #12
0
import unittest
import os, sys

test_dir = os.path.dirname(__file__)
src_dir = "../"
sys.path.insert(0, os.path.abspath(os.path.join(test_dir, src_dir)))

from bank.accounts import Accounts, CheckingAccount, SavingsAccount
from bank.account_holder import AccountHolder
from bank.banks import Bank
from bank.cards import Card
from bank.exceptions import InsufficientBalance, AccountError, ExceedsLimit

bank = Bank()
cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
cormo_checking = CheckingAccount("101-checking-1",
                                 "checking",
                                 cormo.accounts,
                                 "101",
                                 opening_balance=1000.00)
cormo_checking_card = Card(
    cormo,
    cormo_checking,
    "Mathias",
    "Cormann",
    "40001|101-checking-1",
    "0101",
    "12-12-2024",
    "432",
    "active",
)
예제 #13
0
import unittest
import os, sys

test_dir = os.path.dirname(__file__)
src_dir = "../"
sys.path.insert(0, os.path.abspath(os.path.join(test_dir, src_dir)))

from bank.accounts import Accounts, CheckingAccount, SavingsAccount
from bank.account_holder import AccountHolder
from bank.banks import Bank
from bank.cards import Card
from bank.exceptions import InsufficientBalance, AccountError, ExceedsLimit

bank = Bank()
cormo = AccountHolder(bank, "101", "Mathias", "Cormann")
cormo_checking = CheckingAccount("101-checking-1",
                                 "checking",
                                 cormo.accounts,
                                 "101",
                                 opening_balance=1000.00)
cormo_checking_card = Card(
    cormo,
    cormo_checking,
    "Mathias",
    "Cormann",
    "40001|101-checking-1",
    "0101",
    "12-12-2024",
    "432",
    "active",
)