Пример #1
0
def main():
    account = Account(TransactionRepository(Clock()),
                      StatementPrinter(Console()))
    account.deposit(1000)
    account.withdraw(100)
    account.deposit(500)
    account.print_statement()
class AccountTest(TestCase):
    def setUp(self):
        self.clock = mock()
        self.transaction_repository = TransactionRepository(self.clock)

    def test_account_should_store_a_deposit_transaction(self):
        when(self.clock).date_as_string().thenReturn('01/04/2015').thenReturn(
            '02/04/2015').thenReturn('10/04/2015')

        self.transaction_repository.store(100)
        self.transaction_repository.store(-50)
        self.transaction_repository.store(20)

        assert_that(
            self.transaction_repository.all_transactions(),
            contains(a_transaction(100, '01/04/2015'),
                     a_transaction(-50, '02/04/2015'),
                     a_transaction(20, '10/04/2015')))
class AccountTest(TestCase):
    def setUp(self):
        self.clock = mock()
        self.transaction_repository = TransactionRepository(self.clock)

    def test_account_should_store_a_deposit_transaction(self):
        when(self.clock).date_as_string().thenReturn("01/04/2015").thenReturn("02/04/2015").thenReturn("10/04/2015")

        self.transaction_repository.store(100)
        self.transaction_repository.store(-50)
        self.transaction_repository.store(20)

        assert_that(
            self.transaction_repository.all_transactions(),
            contains(
                a_transaction(100, "01/04/2015"), a_transaction(-50, "02/04/2015"), a_transaction(20, "10/04/2015")
            ),
        )
Пример #4
0
    def test_print_statement_containing_all_transactions(self):
        console = mock()
        clock = mock()

        when(clock).date_as_string().thenReturn('01/04/2015').thenReturn(
            '02/04/2015').thenReturn('10/04/2015')

        account = Account(TransactionRepository(clock),
                          StatementPrinter(console))
        account.deposit(1000)
        account.withdraw(100)
        account.deposit(500)

        account.print_statement()

        inorder.verify(console).print_line('DATE | AMOUNT | BALANCE')
        inorder.verify(console).print_line('10/04/2015 | 500.00 | 1400.00')
        inorder.verify(console).print_line('02/04/2015 | -100.00 | 900.00')
        inorder.verify(console).print_line('01/04/2015 | 1000.00 | 1000.00')
 def setUp(self):
     self.clock = mock()
     self.transaction_repository = TransactionRepository(self.clock)
 def setUp(self):
     self.clock = mock()
     self.transaction_repository = TransactionRepository(self.clock)