예제 #1
0
class TestAccount:
    def setup_class(self):
        self.account1 = Account(1)
        self.account2 = Account(2)

    def teardown_class(self):
        pass

    def test_check_balance(self):
        assert self.account1.check_balance() == 0
        assert self.account2.check_balance() == 0

    def test_deposit(self):
        self.account1.deposit(200)
        assert self.account1.check_balance() == 200

    def test_withdraw(self):
        self.account1.withdraw(150)
        assert self.account1.check_balance() == 50

    def test_withdraw_limit(self):
        assert self.account1.withdraw(250) == False

    def test_transfer(self):
        self.account1.deposit(150)
        self.account1.transfer(self.account2, 50)
        assert self.account2.check_balance() == 50
예제 #2
0
    def test_deposit_adds_multiple_transactions(self, mock_transaction_constructor, mock_date):
        mock_transaction = mock_transaction_constructor.return_value
        mock_date.today.side_effect = [
            date(2012, 1, 10),
            date(2012, 1, 13)
        ]

        mock_transaction_history = Mock()
        account = Account(transaction_history=mock_transaction_history)

        account.deposit(1000)
        account.deposit(2000)

        mock_transaction_constructor.assert_has_calls(
            [
                call(1000, date(2012, 1, 10)),
                call(2000, date(2012, 1, 13))
            ]
        )

        mock_transaction_history.add.assert_has_calls(
            [
                call(mock_transaction),
                call(mock_transaction)
            ]
        )
def test_withdrawal_appended_to_transactions():
    """The withdraw instance is appended to transactions"""
    account = Account()
    account.deposit(-300)
    account.withdraw(80)
    account.withdraw(120)
    # all of the withdraw instances or 'transactions' should be in Account(object)
    data = ast.literal_eval(repr(account.transactions))
    assert account.get_balance() == sum(row[0] for row in data)
def test_negative_deposits_converted_to_positive():
    """
    Given a negative amount argument for deposit, the amount value is converted
    to positive.
    """
    account = Account()
    amount = -300
    account.deposit(amount)
    assert account.get_balance() == 300
예제 #5
0
    def test_deposit_adds_one_deposit_transaction(self, mock_transaction_constructor, mock_date):
        mock_transaction = mock_transaction_constructor.return_value
        mock_date.today.return_value = date(2012, 1, 10)
        mock_transaction_history = Mock()

        account = Account(transaction_history=mock_transaction_history)
        account.deposit(1000)

        mock_transaction_constructor.assert_called_with(1000, date(2012, 1, 10))
        mock_transaction_history.add.assert_called_with(mock_transaction)
def test_account_balance_series_of_transactions():
    """
    Given some transaction instances, the balance should be the sum total
    of all transacation instances
    """
    acc = Account()
    acc.deposit(100)
    acc.withdraw(90)
    acc.deposit(10)
    data = ast.literal_eval(repr(acc.transactions))
    assert sum(row[0] for row in data) == 20
예제 #7
0
def test_account():
    test = Account(60, "tester")

    print("Try to add to much interest")
    test.interest(70)
    print("Attempt to over withdrawl account")
    test.withdrawl(70)
    test.withdrawl(60)
    print("Withdrawl almosteverything.", test.pretty_balance())
    test.deposit(60)
    print("New Balanmce should be 63:")
    print(test.pretty_balance())
예제 #8
0
    def test_print_statement_for_one_transaction(self,
            mock_bank_statement_constructor,
            mock_transaction_constructor,
            mock_date
            ):
        mock_transaction = mock_transaction_constructor.return_value
        mock_bank_statement = mock_bank_statement_constructor.return_value
        mock_date.today.return_value = date(2012, 1, 14)

        mock_output = Mock()
        mock_transaction_history = Mock()

        account = Account(transaction_history=mock_transaction_history, output=mock_output)

        account.deposit(500)
        account.print_statement()

        mock_bank_statement_constructor.assert_called_with(mock_transaction_history)
        mock_output.write.assert_called_with(str(mock_bank_statement))
def test_deposit_appended_to_transactions():
    """The deposit instance is appended to transactions"""
    account = Account()
    account.deposit(-300)
    account.deposit(100)
    account.deposit(30.59)
    # all of the deposit instances or 'transactions' are included Account(object)
    data = ast.literal_eval(repr(account.transactions))
    assert sum(row[0] for row in data) == 430.59
예제 #10
0
    if ans == 'y':
        firstname = input("please input the firstname")
        lastname = input("please input the lastname")
        account = input("please input the account")
        names.append(namelist)
    else:
        break
    money = 0
    balance = int(money)
    Balance = Account(balance)
    while True:
        j = int(input("how much do you want withdraw?"))
        Balance.withdraw(j)
        if Balance.getBalance(balance) < 0:
            print("not enough money")
            Balance.deposit(j)
            continue
        else:
            print(Balance.getBalance(balance), "$")

        break

    while True:
        j = input("")
        if j == "1":
            print(customer.account())
            break
        if j == "2":
            print(len(names))
            break
        if j == "3":