Exemple #1
0
class AccountBalanceTestCases(unittest.TestCase):
    def setUp(self):
        self.account_yangu = BankAccount()

    def test_balance(self):
        self.assertEqual(self.account_yangu.balance,
                         3000,
                         msg='Account balance Invalid')

    def test_deposit(self):
        self.account_yangu.deposit(4000)
        self.assertEqual(self.account_yangu.balance,
                         7000,
                         msg='deposit has jam')

    def test_withdraw(self):
        self.account_yangu.withdraw(500)
        self.assertEqual(self.account_yangu.balance,
                         2500,
                         msg='withdraw has jam')

    def test_invalid_trans(self):
        self.assertEqual(self.account_yangu.withdraw(6000),
                         "invalid transaction",
                         msg='invalid transaction')
    def test_transfer_to(self):
        account = BankAccount("Tester", 100, "$")
        result = account.transfer_to(self.account, 70)

        self.assertTrue(result)
        self.assertEqual(self.account.balance(), 70)
        self.assertEqual(account.balance(), 30)
Exemple #3
0
    def test_withdraw(self):
        bank = BankAccount()
        bank.deposit(30)
        bank.withdraw(20)
        self.assertEqual(10, bank.balance())

        with self.assertRaises(InsufficientFunds):
            bank.withdraw(50)
Exemple #4
0
    def test_deposit(self):
        bank = BankAccount()
        bank.deposit(20)
        self.assertEqual(20, bank.balance())

        bank.deposit(15)
        self.assertEqual(35, bank.balance())
def account():
    """
    Creates account with 0 balance.
    :return:
    """
    account = BankAccount()
    return account
Exemple #6
0
class AccountBalanaceTestCase(unittest.TestCase):
    def setUp(self):
        self.user_account = BankAccount()

    def test_balance(self):
        self.assertEqual(self.user_account.balance, 3000, msg='Account Balance Invalid.')

    def test_deposit(self):
        self.user_account.deposit(4000)
        self.assertEqual(self.user_account.balance, 7000, msg='Deposit Method Inaccurate.')

    def test_withdraw(self):
        self.user_account.withdraw(500)
        self.assertEqual(self.user_account.balance, 2500, msg='Withdraw method Inaccurate.')

    def test_invalid_transaction(self):
        self.assertEqual(self.user_account.withdraw(6000), "Invalid Transaction", msg='Invalid Transaction.')
Exemple #7
0
def createAccount():
    # get information from user and generate an id
    owner = input('Enter your name: ')
    balance = float(input('Enter your initial deposit: '))
    id = uuid.uuid4().hex

    # return the new bank account object
    return BankAccount(owner, balance, id)
    def test_history(self):
        account = BankAccount("Test", 0, "$")
        account.deposit(20)
        account.balance()
        int(account)
        expected = ["Account was created", "Deposited 20$",
                    "Balance check -> 20$", "__int__ check -> 20$"]

        self.assertEqual(account.history(), expected)
	def test_history(self):
		account = BankAccount("Test", 0, "$")
		account.deposit(20)
		account.balance()
		int(account)
		expected = ["Account was created", "Deposited 20$","Balance check -> 20$", "__int__ check -> 20$"]

		self.assertEqual(account.history(), expected)
Exemple #10
0
    def test_initial_non_zero_balance(self):
        initial_balance = 100
        account = BankAccount("Test", initial_balance, "$")

        self.assertEqual(account.balance(), initial_balance)
Exemple #11
0
    def test_get_name(self):
        name = "Test"
        account = BankAccount(name, 0, "$")

        self.assertEqual(account.holder(), name)
Exemple #12
0
 def __init__(self, name, email):
     self.name = name
     self.email = email
     self.accounts = {'checking': BankAccount(), 'savings': BankAccount()}
    def test_get_name_when_name_not_string_but_object(self):
        name = ("Radoslav", "Georgiev")
        account = BankAccount(name, 0, "%")

        self.assertEqual(str(name), account.holder())
    def test_currency_always_string(self):
        currency = 1

        account = BankAccount("Test", 0, currency)

        self.assertEqual(str(currency), account.currency())
Exemple #15
0
 def setUp(self):
     self.currency = "BGN"
     self.account = BankAccount("Rado", 0, self.currency)
    def test_initial_non_zero_balance(self):
        initial_balance = 100
        account = BankAccount("Test", initial_balance, "$")

        self.assertEqual(account.balance(), initial_balance)
 def test_deposit_in_not_empty_account(self):
     account = BankAccount("Ivo", 1000, "$")
     account.deposit(500)
     self.assertEqual(account.balance(), 1500)
Exemple #18
0
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.currency = "BGN"
        self.account = BankAccount("Rado", 0, self.currency)

    def test_can_create_bank_account(self):
        self.assertTrue(isinstance(self.account, BankAccount))

    def test_initial_zero_balance(self):
        self.assertEqual(self.account.balance(), 0)

    def test_initial_non_zero_balance(self):
        initial_balance = 100
        account = BankAccount("Test", initial_balance, "$")

        self.assertEqual(account.balance(), initial_balance)

    def test_negative_initial_amount(self):
        with self.assertRaises(ValueError):
            BankAccount("Test", -100, "$")

    def test_get_name(self):
        name = "Test"
        account = BankAccount(name, 0, "$")

        self.assertEqual(account.holder(), name)

    def test_get_name_when_name_not_string_but_object(self):
        name = ("Radoslav", "Georgiev")
        account = BankAccount(name, 0, "%")

        self.assertEqual(str(name), account.holder())

    def test_get_currency(self):
        self.assertEqual(self.account.currency(), self.currency)

    def test_currency_always_string(self):
        currency = 1

        account = BankAccount("Test", 0, currency)

        self.assertEqual(str(currency), account.currency())

    def test_deposit_in_empty_account(self):
        self.account.deposit(100)

        self.assertEqual(100, self.account.balance())

    def test_deposit_in_not_empty_account(self):
        account = BankAccount("Test", 50, "$")
        account.deposit(50)

        self.assertEqual(account.balance(), 100)

    def test_deposit_negative_amount(self):
        with self.assertRaises(ValueError):
            self.account.deposit(-100)

    def test_withdraw_from_non_empty_account(self):
        self.account.deposit(100)
        result = self.account.withdraw(50)

        self.assertTrue(result)
        self.assertEqual(self.account.balance(), 50)

    def test_withdraw_from_empty_account(self):
        result = self.account.withdraw(50)

        self.assertIsNotNone(result)
        self.assertFalse(result)

    def test_history_when_account_is_created(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created"]

        self.assertEqual(account.history(), expected)

    def test_history_with_balance_check(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created", "Balance check -> 0$"]

        self.assertEqual(account.history(), expected)
	def test_deposit_second_test(self):
		account = BankAccount("Ivo",1000, "$")
		account.deposit(500)
		self.assertEqual(account.balance(), 1500)
Exemple #20
0
from bank import BankAccount  # If File name: bank.py and in the same folder

b1 = BankAccount("56789", "Tony", 500.0)
b2 = BankAccount("12345", "Jerry", 190.0)

b1.withdraw(100.0)
b2.deposit(50.0)

print(b1 < b2)
print(b1 > b2)
Exemple #21
0
 def __init__(self, name, email, bank):
     self.name = name
     self.email = email
     self.account = BankAccount(int_rate=0.02, balance=0)
Exemple #22
0
    def test_history_with_balance_check(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created", "Balance check -> 0$"]

        self.assertEqual(account.history(), expected)
Exemple #23
0
    def test_history_when_account_is_created(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created"]

        self.assertEqual(account.history(), expected)
Exemple #24
0
    account_init_balance = account_with_random_balance.get_balance()
    account_with_random_balance.credit(100)
    assert account_with_random_balance.get_balance(
    ) - account_init_balance == 100


def test_when_new_account_is_created_then_balance_is_0(account):
    assert account.get_balance(
    ) == 0, "The balance after account was created should be 0."


def test_when_new_account_is_credited_with_negative_value_then_valueerror_should_raise(
        account):
    with pytest.raises(ValueError):
        account.credit(100)


def test_when_new_account_is_credit_by_100_then_its_balance_should_be_100(
        account):
    account.credit(100)
    assert account.get_balance() == 100


@pytest.mark.parametrize(
    'value',
    [1.23, 'jano', True, BankAccount(), list, None])
def test_when_wrong_type_is_credited_then_exception_TypeError_should_be_raised(
        account, value):
    with pytest.raises(TypeError):
        account.credit(value)
Exemple #25
0
    def test_get_name_when_name_not_string_but_object(self):
        name = ("Radoslav", "Georgiev")
        account = BankAccount(name, 0, "%")

        self.assertEqual(str(name), account.holder())
Exemple #26
0
 def setUp(self):
     self.account_yangu = BankAccount()
Exemple #27
0
    def test_currency_always_string(self):
        currency = 1

        account = BankAccount("Test", 0, currency)

        self.assertEqual(str(currency), account.currency())
 def test_negative_initial_amount(self):
     with self.assertRaises(ValueError):
         BankAccount("Test", -100, "$")
 def test_holder(self):
     account = BankAccount("Tester", 0, "$")
     self.assertEqual(account.holder(), "Tester")
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.account = BankAccount("Rado", 0, "$")

    def test_can_create_bank_account(self):
        self.assertTrue(isinstance(self.account, BankAccount))

    def test_get_name(self):
        self.assertEqual(self.account.holder(), "Rado")

    def test_initial_zero_balance(self):
        self.assertEqual(self.account.balance(), 0)

    def test_negative_initial_amount(self):
        with self.assertRaises(ValueError):
            BankAccount("Test", -100, "$")

    def test_deposit_in_empty_account(self):
        self.account.deposit(500)
        self.assertEqual(self.account.balance(), 500)

    def test_deposit_in_not_empty_account(self):
        account = BankAccount("Ivo", 1000, "$")
        account.deposit(500)
        self.assertEqual(account.balance(), 1500)

    def test_deposit_negative_amount(self):
        with self.assertRaises(ValueError):
            self.account.deposit(-100)

    def test_withdraw_from_not_empty_account(self):
        self.account.deposit(100)
        result = self.account.withdraw(50)

        self.assertTrue(result)
        self.assertEqual(self.account.balance(), 50)

    def test_withdraw_from_empty_account(self):
        result = self.account.withdraw(50)

        self.assertIsNotNone(result)
        self.assertFalse(result)

    def test_history(self):
        account = BankAccount("Test", 0, "$")
        account.deposit(20)
        account.balance()
        int(account)
        expected = ["Account was created", "Deposited 20$",
                    "Balance check -> 20$", "__int__ check -> 20$"]

        self.assertEqual(account.history(), expected)
    def test_withdraw_less_than_you_have(self):
        account = BankAccount("Tester", 100, "$")
        result = account.withdraw(20)

        self.assertTrue(result)
        self.assertEqual(account.balance(), 80)
 def setUp(self):
     self.account = BankAccount("Rado", 0, "$")
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.account = BankAccount("Rado", 0, "$")

    def test_can_create_bank_account(self):
        self.assertTrue(isinstance(self.account, BankAccount))

    def test_balance(self):
        self.assertEqual(self.account.balance(), 0)

    def test_negative_initial_amount(self):
        with self.assertRaises(ValueError):
            BankAccount("Tester", -100, "$")

    def test_int_dunder(sefl):
        sefl.assertEqual(int(sefl.account), 0)

    def test_str_dunder(sefl):
        sefl.assertEqual(str(sefl.account), "Bank account for Rado with balance of 0$")

    def test_holder(self):
        account = BankAccount("Tester", 0, "$")
        self.assertEqual(account.holder(), "Tester")

    def test_currency(self):
        self.assertEqual(self.account.currency(), "$")

    def test_deposit(self):
        self.account.deposit(100)
        self.assertEqual(self.account.balance(), 100)

    def test_deposit_negative_amount(self):
        with self.assertRaises(ValueError):
            self.account.deposit(-100)

    def test_withdraw_less_than_you_have(self):
        account = BankAccount("Tester", 100, "$")
        result = account.withdraw(20)

        self.assertTrue(result)
        self.assertEqual(account.balance(), 80)

    def test_withdraw_more_than_you_have(self):
        result = self.account.withdraw(50)
        self.assertIsNotNone(result)
        self.assertFalse(result)

    def test_transfer_to(self):
        account = BankAccount("Tester", 100, "$")
        result = account.transfer_to(self.account, 70)

        self.assertTrue(result)
        self.assertEqual(self.account.balance(), 70)
        self.assertEqual(account.balance(), 30)

    def test_history_when_account_is_created(self):
        self.assertEqual(self.account.history(), ["Account was created"])

    def test_history_for_int(self):
        int(self.account)
        self.assertEqual(self.account.history(), ["Account was created", "__int__ check -> 0$"])

    def test_history_with_balance_check(self):
        self.account.balance()
        self.assertEqual(self.account.history(), ["Account was created", "Balance check -> 0$"])

    def test_history_for_deposit(self):
        self.account.deposit(1000)
        self.assertEqual(self.account.history(), ["Account was created", "Deposited 1000$"])

    def test_history_for_successful_withdraw(self):
        account = BankAccount("Tester", 100, "$")
        account.withdraw(50)
        self.assertEqual(account.history(), ["Account was created", "50$ was withdrawed"])

    def test_history_for_unsuccessful_withdraw(self):
        self.account.withdraw(50)
        self.assertEqual(self.account.history(), ["Account was created", "Withdraw for 50$ failed."])

    def test_history_for_transfer_to(self):
        account = BankAccount("Tester", 100, "$")
        result = account.transfer_to(self.account, 50)

        self.assertEqual(self.account.history(), ["Account was created", "Transfer from Tester for 50$"])
        self.assertEqual(account.history(), ["Account was created", "Transfer to Rado for 50$"])
Exemple #34
0
 def setUp(self):
     self.user_account = BankAccount()
    def test_history_when_account_is_created(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created"]

        self.assertEqual(account.history(), expected)
    def test_get_name(self):
        name = "Test"
        account = BankAccount(name, 0, "$")

        self.assertEqual(account.holder(), name)
 def test_deposit_in_not_empty_account(self):
     account = BankAccount("Ivo", 1000, "$")
     account.deposit(500)
     self.assertEqual(account.balance(), 1500)
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.currency = "BGN"
        self.account = BankAccount("Rado", 0, self.currency)

    def test_can_create_bank_account(self):
        self.assertTrue(isinstance(self.account, BankAccount))

    def test_initial_zero_balance(self):
        self.assertEqual(self.account.balance(), 0)

    def test_initial_non_zero_balance(self):
        initial_balance = 100
        account = BankAccount("Test", initial_balance, "$")

        self.assertEqual(account.balance(), initial_balance)

    def test_negative_initial_amount(self):
        with self.assertRaises(ValueError):
            BankAccount("Test", -100, "$")

    def test_get_name(self):
        name = "Test"
        account = BankAccount(name, 0, "$")

        self.assertEqual(account.holder(), name)

    def test_get_name_when_name_not_string_but_object(self):
        name = ("Radoslav", "Georgiev")
        account = BankAccount(name, 0, "%")

        self.assertEqual(str(name), account.holder())

    def test_get_currency(self):
        self.assertEqual(self.account.currency(), self.currency)

    def test_currency_always_string(self):
        currency = 1

        account = BankAccount("Test", 0, currency)

        self.assertEqual(str(currency), account.currency())

    def test_deposit_in_empty_account(self):
        self.account.deposit(100)

        self.assertEqual(100, self.account.balance())

    def test_deposit_in_not_empty_account(self):
        account = BankAccount("Test", 50, "$")
        account.deposit(50)

        self.assertEqual(account.balance(), 100)

    def test_deposit_negative_amount(self):
        with self.assertRaises(ValueError):
            self.account.deposit(-100)

    def test_withdraw_from_non_empty_account(self):
        self.account.deposit(100)
        result = self.account.withdraw(50)

        self.assertTrue(result)
        self.assertEqual(self.account.balance(), 50)

    def test_withdraw_from_empty_account(self):
        result = self.account.withdraw(50)

        self.assertIsNotNone(result)
        self.assertFalse(result)

    def test_history_when_account_is_created(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created"]

        self.assertEqual(account.history(), expected)

    def test_history_with_balance_check(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created", "Balance check -> 0$"]

        self.assertEqual(account.history(), expected)
 def setUp(self):
     self.account = BankAccount("Rado", 0, "$")
 def setUp(self):
     self.currency = "BGN"
     self.account = BankAccount("Rado", 0, self.currency)
Exemple #41
0
def account_with_random_balance():
    account = BankAccount()
    account.credit(random.randint(100, 200))
    return account
    def test_history_with_balance_check(self):
        account = BankAccount("Test", 0, "$")
        expected = ["Account was created", "Balance check -> 0$"]

        self.assertEqual(account.history(), expected)
 def test_history_for_successful_withdraw(self):
     account = BankAccount("Tester", 100, "$")
     account.withdraw(50)
     self.assertEqual(account.history(), ["Account was created", "50$ was withdrawed"])
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.account = BankAccount("Rado", 0, "$")

    def test_can_create_bank_account(self):
        self.assertTrue(isinstance(self.account, BankAccount))

    def test_get_name(self):
        self.assertEqual(self.account.holder(), "Rado")

    def test_initial_zero_balance(self):
        self.assertEqual(self.account.balance(), 0)

    def test_negative_initial_amount(self):
        with self.assertRaises(ValueError):
            BankAccount("Test", -100, "$")

    def test_deposit_in_empty_account(self):
        self.account.deposit(500)
        self.assertEqual(self.account.balance(), 500)

    def test_deposit_in_not_empty_account(self):
        account = BankAccount("Ivo", 1000, "$")
        account.deposit(500)
        self.assertEqual(account.balance(), 1500)

    def test_deposit_negative_amount(self):
        with self.assertRaises(ValueError):
            self.account.deposit(-100)

    def test_withdraw_from_not_empty_account(self):
        self.account.deposit(100)
        result = self.account.withdraw(50)

        self.assertTrue(result)
        self.assertEqual(self.account.balance(), 50)

    def test_withdraw_from_empty_account(self):
        result = self.account.withdraw(50)

        self.assertIsNotNone(result)
        self.assertFalse(result)

    def test_history(self):
        account = BankAccount("Test", 0, "$")
        account.deposit(20)
        account.balance()
        int(account)
        expected = ["Account was created", "Deposited 20$",
                    "Balance check -> 20$", "__int__ check -> 20$"]

        self.assertEqual(account.history(), expected)

    def test_transfer(self):
        account1 = BankAccount("Rado", 100, "$")
        account2 = BankAccount("Ivo", 0, "$")
        result = account1.transfer_to(account2, 50)
        self.assertTrue(result)
    def test_history_for_transfer_to(self):
        account = BankAccount("Tester", 100, "$")
        result = account.transfer_to(self.account, 50)

        self.assertEqual(self.account.history(), ["Account was created", "Transfer from Tester for 50$"])
        self.assertEqual(account.history(), ["Account was created", "Transfer to Rado for 50$"])
 def test_transfer(self):
     account1 = BankAccount("Rado", 100, "$")
     account2 = BankAccount("Ivo", 0, "$")
     result = account1.transfer_to(account2, 50)
     self.assertTrue(result)
Exemple #47
0
 def create_account(self, account_type, initial_amount=0):
     self.accounts[account_type] = BankAccount(initial_amount)