Пример #1
0
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
Пример #2
0
 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
Пример #3
0
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)
Пример #4
0
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
Пример #5
0
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
Пример #6
0
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)
Пример #7
0
def new_random_account():
    account = Account.create(UniqueID(), UniqueID(), UniqueID(), 'test')
    return account
Пример #8
0
def test_create_function_returns_new_account():
    account = Account.create(UniqueID(), UniqueID(), UniqueID(), 'test')
    assert isinstance(account, Account)
Пример #9
0
def new_random_account_unlimited_debt():
    account = Account.create(UniqueID(), UniqueID(), UniqueID(), 'test')
    account.set_maximum_debt(Amount(999999999999999, 0), UniqueID())
    return account
Пример #10
0
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())
Пример #11
0
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
Пример #12
0
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)