Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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_not_should_start_a_bank_draft_when_the_target_is_an_invalid_account(self):

        target = "Hype"
        transferamount = Amount(100)

        with self.assertRaises(TypeError):
            BankDraft(target, transferamount)
Exemplo n.º 9
0
    def test_should_not_be_created_bank_account_with_invalid_account_type(
            self):

        balance = Amount(0)

        with self.assertRaises(TypeError):
            BankAccount("123", balance, 22)
Exemplo n.º 10
0
    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_not_should_start_a_bank_deposit_when_the_receiver_is_an_invalid_account(
            self):

        receiver = "ibrain"
        transferamount = Amount(100)

        with self.assertRaises(TypeError):
            BankDeposit(receiver, transferamount)
    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()
Exemplo n.º 14
0
    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)
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    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_not_should_register_a_bank_transaction_when_the_amount_is_invalid(
            self):

        whenoccurred = datetime.now()
        amount = Amount(100)
        description = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

        with self.assertRaises(TypeError):
            BankTransactionRecord(BankOperationType.DEPOSIT, "123",
                                  whenoccurred, amount, description, 1)
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
    def execute(self, targetaccountnumber, withdrawamount):

        #Validar targetaccountnumber
        withdrawamount = Amount(withdrawamount)

        targetaccount = self.__bankaccountrepository.findperaccountnumber(
            targetaccountnumber)
        bankdraft = BankDraft(targetaccount, withdrawamount)
        banktransactionrecord = bankdraft.towithdraw()

        self.__bankaccountrepository.update(targetaccount)
        self.__banktransactionrecordrepository.add(banktransactionrecord)
        self.__session.commit()
Exemplo n.º 21
0
    def execute(self, receiveraccountnumber, depositamount):

        #Validar targetaccountnumber
        depositamount = Amount(depositamount)

        receiveraccount = self.__bankaccountrepository.findperaccountnumber(
            receiveraccountnumber)
        bankdeposit = BankDeposit(receiveraccount, depositamount)
        banktransactionrecord = bankdeposit.todeposit()

        self.__bankaccountrepository.update(receiveraccount)
        self.__banktransactionrecordrepository.add(banktransactionrecord)
        self.__session.commit()
Exemplo n.º 22
0
    def execute(self, senderaccountnumber, receiveraccountnumber,
                transferamount):

        #Validar targetaccountnumber
        transferamount = Amount(transferamount)

        senderaccount = self.__bankaccountrepository.findperaccountnumber(
            senderaccountnumber)
        receiveraccount = self.__bankaccountrepository.findperaccountnumber(
            receiveraccountnumber)

        banktransfer = BankTransfer(senderaccount, receiveraccount,
                                    transferamount)
        banktransactionrecords = banktransfer.transfer()

        self.__bankaccountrepository.update(senderaccount)
        self.__bankaccountrepository.update(receiveraccount)
        self.__banktransactionrecordrepository.addmultiple(
            banktransactionrecords)
        self.__session.commit()
Exemplo n.º 23
0
 def __init__(self):
     self.__CHECKING_LIMIT_WITHDRAWAL = Amount(6000)
     self.__CHECKING_LIMIT_RECEIVE = Amount(8000)
Exemplo n.º 24
0
 def __init__(self):
     self.__SAVINGS_LIMIT_WITHDRAWAL = Amount(2500)
     self.__SAVINGS_LIMIT_RECEIVE = Amount(5000)