def test_should_not_withdraw_an_amount_when_amount_is_invalid(self): initialbalance = Amount(100) account = BankAccount("123", initialbalance, AccountType.SAVINGS) withdrawamount = 10 with self.assertRaises(TypeError): account.withdraw(withdrawamount)
def test_should_not_receive_an_amount_when_amount_is_invalid(self): initialbalance = Amount(0) account = BankAccount("123", initialbalance, AccountType.SAVINGS) receiveAmount = 100 with self.assertRaises(TypeError): account.receive(receiveAmount)
def test_should_not_withdraw_an_amount_when_the_balance_amount_is_less_that_amount( self): initialbalance = Amount(100) account = BankAccount("123", initialbalance, AccountType.SAVINGS) withdrawamount = Amount(1000000) with self.assertRaises(ValueError): account.withdraw(withdrawamount)
def test_not_should_start_a_bank_transfer_when_the_transfer_amount_is_an_invalid( self): senderamount = Amount(1000) sender = BankAccount("123", senderamount, AccountType.CHECKING) receiveramount = Amount(2000) receiver = BankAccount("123", receiveramount, AccountType.SAVINGS) transferamount = 750 with self.assertRaises(TypeError): BankTransfer(sender, receiver, transferamount)
def test_should_withdraw_an_amount_and_decrease_the_current_amount(self): initialbalance = Amount(100) account = BankAccount("123", initialbalance, AccountType.SAVINGS) withdrawamount = Amount(10) account.withdraw(withdrawamount) newbalance = account.getbalance() expectedbalance = (initialbalance - withdrawamount) self.assertEqual(newbalance, expectedbalance)
def test_should_receive_an_amount_and_increase_the_current_amount(self): initialbalance = Amount(0) account = BankAccount("123", initialbalance, AccountType.SAVINGS) receiveAmount = Amount(100) account.receive(receiveAmount) newbalance = account.getbalance() expectedbalance = (initialbalance + receiveAmount) self.assertEqual(newbalance, expectedbalance)
def test_should_not_be_created_bank_account_with_invalid_account_type( self): balance = Amount(0) with self.assertRaises(TypeError): BankAccount("123", balance, 22)
def test_should_be_created_bank_account_in_valid_state(self): balance = Amount(0) account = BankAccount("123", balance, AccountType.SAVINGS) self.assertIsInstance(account, BankAccount) self.assertIsNotNone(account)
def test_should_to_withdraw_a_amount_in_a_account(self): initialbalance = Amount(1000) target = BankAccount("123", initialbalance, AccountType.SAVINGS, 10) transferamount = Amount(100) bankdraft = BankDraft(target, transferamount) withdrawrecord = bankdraft.towithdraw() newbalance = target.getbalance() expectedbalance = (initialbalance - transferamount) self.assertEqual(newbalance, expectedbalance) self.assertEqual(withdrawrecord.getamount(), -int(transferamount)) self.assertEqual(withdrawrecord.getoperation(), BankOperationType.WITHDRAW)
def test_should_deposit_a_amount_in_a_account(self): initialbalance = Amount(1000) receiver = BankAccount("123", initialbalance, AccountType.CHECKING, 10) transferamount = Amount(100) bankdeposit = BankDeposit(receiver, transferamount) depositrecord = bankdeposit.todeposit() newbalance = receiver.getbalance() expectedbalance = (initialbalance + transferamount) self.assertEqual(newbalance, expectedbalance) self.assertEqual(depositrecord.getamount(), int(transferamount)) self.assertEqual(depositrecord.getoperation(), BankOperationType.DEPOSIT)
def execute(self, balance, accounttype): number = str(random.randint(1, 999999999999999999)) balance = Amount(balance) accounttype = AccountType(accounttype) newbankaccount = BankAccount(number, balance, accounttype) self.__bankaccountrepository.add(newbankaccount) self.__session.commit()
def test_not_should_start_a_bank_draft_when_the_transfer_amount_is_an_invalid(self): balance = Amount(1000) target = BankAccount("123", balance, AccountType.SAVINGS) transferamount = 100 with self.assertRaises(TypeError): BankDraft(target, transferamount)
def test_not_should_start_a_bank_deposit_when_the_transfer_amount_is_an_invalid( self): balance = Amount(1000) receiver = BankAccount("123", balance, AccountType.CHECKING) transferamount = 100 with self.assertRaises(TypeError): BankDeposit(receiver, transferamount)
def test_not_should_start_a_bank_transfer_when_the_sender_is_an_invalid_account( self): sender = "receiver" receiveramount = Amount(2000) receiver = BankAccount("123", receiveramount, AccountType.SAVINGS) transferamount = Amount(750) with self.assertRaises(TypeError): BankTransfer(sender, receiver, transferamount)
def findperaccountnumber(self, targetaccountnumber): bankcccountmap = self.__session.query(BankAccountMap).filter_by( number=targetaccountnumber).first() # TODO: Possible encapsulation number = targetaccountnumber balance = Amount(bankcccountmap.balance) accounttype = AccountType(bankcccountmap.type) id = bankcccountmap.id return BankAccount(number, balance, accounttype, id)
def test_should_transfer_a_amount_between_two_accounts(self): senderinitialamount = Amount(1000) sender = BankAccount("123", senderinitialamount, AccountType.CHECKING, 10) receiverinitialamount = Amount(2000) receiver = BankAccount("123", receiverinitialamount, AccountType.SAVINGS, 12) transferamount = Amount(750) banktransfer = BankTransfer(sender, receiver, transferamount) transferrecord = banktransfer.transfer() expectedamountsender = (senderinitialamount - transferamount) senderbalance = sender.getbalance() expectedamountreceiver = (receiverinitialamount + transferamount) receiverbalance = receiver.getbalance() transferrecordsender = transferrecord[0] transferrecordreceiver = transferrecord[1] self.assertEqual(expectedamountsender, senderbalance) self.assertEqual(expectedamountreceiver, receiverbalance) self.assertEqual(transferrecordsender.getamount(), -int(transferamount)) self.assertEqual(transferrecordsender.getoperation(), BankOperationType.TRANSFER) self.assertEqual(transferrecordreceiver.getamount(), int(transferamount)) self.assertEqual(transferrecordreceiver.getoperation(), BankOperationType.TRANSFER)
def test_should_not_be_created_bank_account_with_invalid_balance(self): balance = "123" with self.assertRaises(TypeError): BankAccount("123", balance, AccountType.SAVINGS)