initial commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
from unittest.mock import patch
|
||||
import pytest
|
||||
from banking import BankAccount
|
||||
|
||||
|
||||
@pytest.mark.parametrize("amount, expected", [
|
||||
(1, 100_001),
|
||||
(99_999, 199_999),
|
||||
(100_000, 200_000),
|
||||
(100_001, 200_001),
|
||||
])
|
||||
def test_deposit_bva(account, amount, expected):
|
||||
assert account.deposit(amount) == expected
|
||||
|
||||
|
||||
def test_deposit_zero_raises(account):
|
||||
with pytest.raises(ValueError, match="Deposit must be positive"):
|
||||
account.deposit(0)
|
||||
|
||||
|
||||
def test_deposit_negative_raises(account):
|
||||
with pytest.raises(ValueError, match="Deposit must be positive"):
|
||||
account.deposit(-1)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("amount, expected", [
|
||||
(1, 99_999),
|
||||
(99_999, 1),
|
||||
(100_000, 0),
|
||||
])
|
||||
def test_withdraw_valid_boundaries(account, amount, expected):
|
||||
assert account.withdraw(amount) == expected
|
||||
|
||||
|
||||
def test_withdraw_zero_raises(account):
|
||||
with pytest.raises(ValueError, match="Withdrawal must be positive"):
|
||||
account.withdraw(0)
|
||||
|
||||
|
||||
def test_withdraw_over_balance_raises(account):
|
||||
with pytest.raises(ValueError, match="Insufficient funds"):
|
||||
account.withdraw(100_001)
|
||||
assert account.balance == 100_000
|
||||
|
||||
|
||||
def test_transfer_and_notification_mock(account):
|
||||
recipient = BankAccount("Bob", 10_000)
|
||||
with patch("banking.send_notification") as mocked:
|
||||
assert account.transfer(recipient, 40_000) == 60_000
|
||||
assert recipient.balance == 50_000
|
||||
mocked.assert_called_once_with("Bob", "Received 40000 from Alice")
|
||||
|
||||
|
||||
def test_transfer_insufficient_funds_does_not_notify(account):
|
||||
recipient = BankAccount("Bob")
|
||||
with patch("banking.send_notification") as mocked:
|
||||
with pytest.raises(ValueError, match="Insufficient funds"):
|
||||
account.transfer(recipient, 100_001)
|
||||
mocked.assert_not_called()
|
||||
assert account.balance == 100_000
|
||||
assert recipient.balance == 0
|
||||
|
||||
|
||||
def test_transfer_zero_raises(account):
|
||||
with pytest.raises(ValueError, match="Transfer must be positive"):
|
||||
account.transfer(BankAccount("Bob"), 0)
|
||||
|
||||
|
||||
def test_transfer_to_self_raises(account):
|
||||
with pytest.raises(ValueError, match="Cannot transfer to the same account"):
|
||||
account.transfer(account, 100)
|
||||
|
||||
|
||||
def test_blank_owner_raises():
|
||||
with pytest.raises(ValueError, match="Owner is required"):
|
||||
BankAccount(" ")
|
||||
|
||||
|
||||
def test_negative_initial_balance_raises():
|
||||
with pytest.raises(ValueError, match="Initial balance cannot be negative"):
|
||||
BankAccount("Alice", -1)
|
||||
Reference in New Issue
Block a user