class TestUseCaseCustomerWithdrawFundsExistingAccount(unittest.TestCase):
    """Allow the customer to withdraw funds from an existing account."""
    def setUp(self):
        self.accountRepository = AccountRepository()
        self.withdrawFund = WithDrawFund(self.accountRepository)

    def test_allow_the_customer_to_withdraw_funds_from_an_existing_account(
            self):
        self._given_an_existing_account()
        self._when_customer_withdraw_from_existing_account()
        self._then_verify_whether_account_has_balance()

    def _given_an_existing_account(self):
        self.idAccount = 1
        idCustomer = 1
        account = Account.create(self.idAccount, idCustomer)
        account.makeCredit(300, 'A deposit of 300')
        self.accountRepository.save(account)

    def _when_customer_withdraw_from_existing_account(self):
        amount = 10
        description = 'A withdraw of 10 from ATM'
        self.withdrawFund.execute(self.idAccount, amount, description)

    def _then_verify_whether_account_has_balance(self):
        account = self.accountRepository.findById(self.idAccount)
        self.assertEqual(account.balance, 290)
Exemplo n.º 2
0
class WithdrawController(APIView):

    def __init__(self):
        self.accountRepository = AccountRepository()
        self.withDraw = WithDrawFund(self.accountRepository)

    def post(self, request, format=None):
        account_id = request.data.get('account_id')
        amount = request.data.get('amount')
        description = request.data.get('description')
        try:
            self.withDraw.execute(account_id, int(amount), description)
            return Response(status=status.HTTP_200_OK)
        except:
            raise WithdawMoreThanExistingFunds
Exemplo n.º 3
0
class TestUseCaseDontAllowWithdrawMorThanExistingFunds(unittest.TestCase):
    def setUp(self):
        self.accountRepository = AccountRepository()
        self.withdrawFund = WithDrawFund(self.accountRepository)

    def test_do_not_allow_the_Customer_to_Withdraw_more_than_the_existing_funds(
            self):
        self._given_an_existing_account()
        self._when_customer_withdraw_from_existing_account()

    def _given_an_existing_account(self):
        idAccount = 1
        idCustomer = 1
        self.account = Account.create(idAccount, idCustomer)
        self.account.makeCredit(300, 'A deposit of 300')

    def _when_customer_withdraw_from_existing_account(self):
        amount = 400
        description = 'A withdraw of 400 from ATM'
        with self.assertRaises(DontAllowWithdawMoreThanExistingFunds):
            self.withdrawFund.execute(self.account, amount, description)
 def setUp(self):
     self.accountRepository = AccountRepository()
     self.withdrawFund = WithDrawFund(self.accountRepository)
Exemplo n.º 5
0
 def __init__(self):
     self.accountRepository = AccountRepository()
     self.withDraw = WithDrawFund(self.accountRepository)