class Unittest(TestCase): def setUp(self): # given self.atm = Atm(CashBox(cash=1000, limit=5000)) card = MagicMock() card.card_holder = MagicMock() card.card_holder.accounts = [MagicMock()] card.card_holder.accounts[0].balance = 2000 self.atm.insert_card(card) self.atm.enter_pin('1') def test_enter_valid_index(self): # when self.atm.select_account(0) # then self.assertEqual(AtmAccountSelected.get_name(), self.atm.get_current_state_name()) def test_enter_invalid_index(self): # when self.atm.select_account(2) # then self.assertEqual(AtmAuthorized.get_name(), self.atm.get_current_state_name())
class TestAtm(unittest.TestCase): def setUp(self): self.atm = Atm() self.atm.enter_pin(777) def test_atm_gives_money(self): money = self.atm.get_money(1000) self.assertEqual(1000, money)
class TestAtmExceptions(unittest.TestCase): def setUp(self): self.atm = Atm() self.atm.enter_pin(777) def test_exception(self): try: self.atm.get_money(1000000) except Exception as e: self.assertEqual('Atm balance is no enough!!!', e.message)
class TestAtm(unittest.TestCase): def setUp(self): self.atm = Atm() self.atm.enter_pin(777) def test_enter_true_pin_and_check_balance(self): '''Enter the correct pin and check the balance''' balance = self.atm.check_balance() self.assertEqual(10000, balance) def test_gives_4000_money(self): '''Give money in the amount of 4000''' money = self.atm.get_money(4000) self.assertEqual(4000, money) def test_gives_10000_money(self): '''Give money in the amount of 10000''' money = self.atm.get_money(10000) self.assertEqual(10000, money) def test_gives_9999_money(self): '''Give money in the amount of 9999''' money = self.atm.get_money(9999) self.assertEqual(9999, money) def test_gives_0_money(self): '''Give money in the amount of 0''' money = self.atm.get_money(0) self.assertEqual(0, money) @unittest.skip("Bug #0001") def test_gives_min_1_money(self): '''A negative amount is given''' money = self.atm.get_money(-1) self.assertEqual(0, money) def test_rise_1000000_money(self): '''Add the amount of 1000000''' rise_money = self.atm._rise_money(1000000) self.assertEqual(1010000, rise_money) def test_rise_0_money(self): '''Add the amount of 0''' rise_money = self.atm._rise_money(0) self.assertEqual(10000, rise_money) @unittest.skip("Bug #0002") def test_rise_min_1_money(self): '''A negative amount is added''' rise_money = self.atm._rise_money(-1) self.assertEqual(10000, rise_money)
class Unittest(TestCase): def setUp(self): # given self.atm = Atm(CashBox(cash=1000, limit=5000)) card = MagicMock() card.card_holder = MagicMock() account = MagicMock() account.balance = 100 card.card_holder.accounts = [account] card.card_holder.accounts[0].balance = 2000 self.atm.insert_card(card) self.atm.enter_pin('1') self.atm.select_account(0) def test_select_menu(self): # when self.atm.select_withdraw() # then self.assertEqual( AtmPreProcessingWithdrawal.get_name(), self.atm.get_current_state_name() ) def test_put_valid_amount(self): # when self.atm.select_withdraw() self.atm.enter_withdrawal_amount(100) self.atm.take_out_cash(100) # then self.assertEqual( AtmDisplayingBalance.get_name(), self.atm.get_current_state_name() ) def test_put_invalid_amount(self): # when self.atm.select_withdraw() self.atm.enter_withdrawal_amount(-100) self.atm.take_out_cash(100) # then self.assertEqual( AtmExit.get_name(), self.atm.get_current_state_name() )
class TestAtmExceptions(unittest.TestCase): def setUp(self): self.atm = Atm() self.atm.enter_pin(777) self.atm2 = Atm() def test_gives_10001_money(self): '''Trying to give the amount more available''' try: self.atm.get_money(10001) except Exception as e: self.assertEqual('Atm balance is no enough!!!', e.message) def test_incorrect_pin(self): '''Testing an incorrect pin''' try: self.atm2.enter_pin(77) except Exception as e: self.assertEqual('Incorrect Pin!!!', e.message)
class Unittest(TestCase): def setUp(self): # given self.atm = Atm(CashBox(cash=1000, limit=2000)) card = MagicMock() card.card_holder = MagicMock() account = MagicMock() account.balance = 100 card.card_holder.accounts = [account] card.card_holder.accounts[0].balance = 3000 self.atm.insert_card(card) self.atm.enter_pin('1') self.atm.select_account(0) def test_cash_box_overflow(self): # when self.atm.select_deposit() self.atm.put_in_cash(1500) # then self.assertEqual( AtmExit.get_name(), self.atm.get_current_state_name() ) def test_enter_overflow2(self): # when self.atm.select_withdraw() self.atm.enter_withdrawal_amount(1500) self.atm.take_out_cash(1500) # then self.assertEqual( AtmExit.get_name(), self.atm.get_current_state_name() )
class TestAtmPinBlock(unittest.TestCase): """ Testing block with a pin input """ def setUp(self): self.term = Atm() def test_input_correct_pin_and_get_balance(self): self.term.enter_pin(777) bal = self.term.check_balance() self.assertEqual(bal, 10000) def test_input_wrong_pin_three_times_and_get_error_message(self): try: self.term.enter_pin(111) self.term.enter_pin(111) self.term.enter_pin(111) except IncorrectPin as e: pass except AttemptsOver as e: self.assertEqual('Attempts are over!!!', e.message) def test_input_wrong_pin_two_times_then_correct_and_get_balance(self): try: self.term.enter_pin(111) self.term.enter_pin(111) self.term.enter_pin(777) bal = self.term.check_balance() self.assertEqual(bal, 10000) except IncorrectPin as e: pass def test_input_pin_value_more_than_three_characters(self): try: self.term.enter_pin(8888) except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_less_than_three_characters(self): try: self.term.enter_pin(88) except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_string(self): try: self.term.enter_pin("something") except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_char(self): try: self.term.enter_pin('A') except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_empty(self): try: self.term.enter_pin("") except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_input_pin_value_space(self): try: self.term.enter_pin(" ") except Exception as e: self.assertEqual("Incorrect Pin!!!", e.message) def test_without_input_pin_check_balance(self): try: self.term.check_balance() except Exception as e: self.assertEqual("Enter pin first!!!", e.message) def test_without_input_pin_get_money(self): try: self.term.get_money(1000) except Exception as e: self.assertEqual("Enter pin first!!!", e.message) def test_without_input_pin_rise_money(self): try: self.term._rise_money(1000) except Exception as e: self.assertEqual("Enter pin first!!!", e.message)
class TestAtmMoneyBlock(unittest.TestCase): """ Testing block with a cash transactions """ def setUp(self): self.term = Atm() self.term.enter_pin(777) def test_rise_money(self): rise = self.term._rise_money(1000) self.assertEqual(rise, 11000) def test_get_money(self): get = self.term.get_money(1000) balance = self.term.check_balance() self.assertEqual(balance, 10000 - get) def test_rise_money_with_negative_value(self): try: self.term._rise_money(-1000) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_zero_value(self): try: self.term._rise_money(0) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_very_big_value(self): try: self.term._rise_money(999999999) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_string_value(self): try: self.term._rise_money("Something") except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_rise_money_with_character_value(self): try: self.term._rise_money('A') except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_negative_value(self): try: self.term.get_money(-1000) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_zero_value(self): try: self.term.get_money(0) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_very_big_value(self): try: self.term.get_money(999999999) except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_string_value(self): try: self.term.get_money("Something") except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message) def test_get_money_with_character_value(self): try: self.term.get_money('A') except Exception as e: self.assertEqual("Atm balance is no enough!!!", e.message)