def test_credit_adds_account_credited_event_to_uncommitted_changes( new_random_account, related_random_account_created_event, new_random_account_credit_event): account = Account(EventStream([related_random_account_created_event])) amount = Amount(new_random_account_credit_event.dollars, new_random_account_credit_event.cents) account.credit(amount, UniqueID(new_random_account_credit_event.operation_id)) assert account.uncommitted_changes[-1] == new_random_account_credit_event
def wrapped(target_id): if account_id == target_id: account_created = AccountCreated( operation_id=str(UniqueID()), account_id=str(UniqueID()), client_id=account_id, account_name='test' ) account = Account(EventStream([account_created])) account.set_maximum_debt(Amount(500, 0), UniqueID()) return account return None
def test_loading_account_from_created_and_credited_events_adds_to_balance( new_random_account, related_random_account_created_event): credited_event = get_account_credited_event(new_random_account.account_id, Amount(50, 42)) account = Account( EventStream([related_random_account_created_event, credited_event])) assert account.balance == Amount(50, 42)
def test_loading_account_from_created_credited_debited_adds_to_balance( new_random_account, related_random_account_created_event, new_random_account_credit_event, new_random_account_debit_event): account = Account( EventStream([ related_random_account_created_event, new_random_account_credit_event, new_random_account_debit_event ])) amount_credit = Amount(new_random_account_credit_event.dollars, new_random_account_credit_event.cents) amount_debit = Amount(new_random_account_debit_event.dollars, new_random_account_debit_event.cents) final = amount_credit - amount_debit assert account.balance == final
def new_account(): account = Account.create(UniqueID(), UniqueID(), UniqueID(), 'test') account.set_maximum_debt(Amount(600), UniqueID()) account.debit(Amount(120), UniqueID()) account.credit(Amount(700), UniqueID()) return account
def test_loading_account_with_only_created_event_has_zero_balance( related_random_account_created_event): account = Account(EventStream([related_random_account_created_event])) assert account.balance == Amount(0, 0)
def new_random_account(): account = Account.create(UniqueID(), UniqueID(), UniqueID(), 'test') return account
def test_create_function_returns_new_account(): account = Account.create(UniqueID(), UniqueID(), UniqueID(), 'test') assert isinstance(account, Account)
def new_random_account_unlimited_debt(): account = Account.create(UniqueID(), UniqueID(), UniqueID(), 'test') account.set_maximum_debt(Amount(999999999999999, 0), UniqueID()) return account
def test_account_maximum_debt_cannot_be_lower_than_0(): with pytest.raises(ValueError): account = Account.create(UniqueID(), UniqueID(), UniqueID(), 'test') account.set_maximum_debt(Amount(-100, -65), UniqueID())
def new_random_account_with_high_maximum_debt(): account = Account.create(UniqueID(), UniqueID(), UniqueID(), 'test') account.set_maximum_debt(Amount(500, 24), UniqueID()) return account
def test_credit_increases_balance(related_random_account_created_event): account = Account(EventStream([related_random_account_created_event])) account.credit(Amount(120, 65), UniqueID()) assert account.balance == Amount(120, 65)