Пример #1
0
def test_feature_print_balance_after_two_deposits_and_one_withdraw(capsys):
    date = datetime.now().strftime("%m/%d/%Y")
    account = Account()
    account.deposit(1000)
    account.deposit(2000)
    account.withdraw(500)
    account.print_statement()
    out, err = capsys.readouterr()
    transaction1 = f"{date} || 1000.00 || || 1000.00"
    transaction2 = f"{date} || 2000.00 || || 3000.00"
    transaction3 = f"{date} || || 500.00 || 2500.00"

    assert out == f"date || credit || debit || balance\n{transaction3}\n{transaction2}\n{transaction1}\n"
    assert err == ""
    def test_user_can_print_account_statement(self):
        """
        Integration statement output
        date       || credit  || debit   || balance
        14/01/2012 ||         || 200.00  || 0.00   
        20/02/2015 || 50.55   ||         || 200.00 
        21/02/2012 ||         || 3000.00 || 149.45 
        01/03/2015 || 3.50    ||         || 3149.45
        11/01/2016 || 10.20   ||         || 3145.95
        """

        printer = Printer()
        account = Account(Transaction, printer)

        account.deposit(200)
        account.withdraw(50.55)
        account.deposit(3000)
        account.withdraw(3.5)
        account.withdraw(10.20)

        statement = ("date       || credit  || debit   || balance"
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " ||         || 200.00  || 0.00   "
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " || 50.55   ||         || 200.00 "
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " ||         || 3000.00 || 149.45 "
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " || 3.50    ||         || 3149.45"
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " || 10.20   ||         || 3145.95")

        self.assertEqual(account.print_statement(), statement)
Пример #3
0
def test_withdraw_raises_an_error_if_not_enough_balance():
    account = Account()
    
    with pytest.raises(NotEnoughMoney):
        account.withdraw(1)
Пример #4
0
def test_withdraw_returns_current_balance():
    account = Account()
    account.deposit(1)

    assert account.withdraw(1) == 0