예제 #1
0
def test_greater_even_to():
    amount1 = Amount(50, 23)
    amount2 = Amount(20, 1)
    assert amount1 >= amount2
    amount1 = Amount(20, 44)
    amount2 = Amount(20, 44)
    assert amount1 >= amount2
예제 #2
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)
예제 #3
0
def test_maximum_debt_cannot_be_lower_than_balance(
        new_random_account_with_high_maximum_debt):
    new_random_account_with_high_maximum_debt.debit(
        new_random_account_with_high_maximum_debt.maximum_debt / Amount(2, 0),
        UniqueID())
    with pytest.raises(ValueError):
        new_random_account_with_high_maximum_debt.set_maximum_debt(
            new_random_account_with_high_maximum_debt.maximum_debt /
            Amount(3, 0), UniqueID())
예제 #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 test_get_by_id_applies_event_stream(account_repo, fake_event_store):
    account_id = UniqueID()
    fake_event_store.load_stream = MagicMock(
        side_effect=return_based_on_id(account_id))
    account = account_repo.get_by_id(account_id)
    assert account.balance == Amount(20)
    assert account.version == 2
예제 #6
0
def test_debit_adds_account_debited_event_to_uncommitted_changes(
        new_random_account_unlimited_debt, new_random_account_debit_event):
    amount = Amount(new_random_account_debit_event.dollars,
                    new_random_account_debit_event.cents)
    new_random_account_unlimited_debt.debit(amount, UniqueID())
    assert isinstance(
        new_random_account_unlimited_debt.uncommitted_changes[-1],
        AccountDebited)
예제 #7
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
예제 #8
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
예제 #9
0
def test_division_divider_greater_than_divided():
    assert Amount(1, 50) / Amount(5, 70) == Amount(1, 50)
예제 #10
0
def test_division_dollars_zero_in_divided():
    assert Amount(0, 60) / Amount(0, 30) == Amount(0, 2)
예제 #11
0
def test_division_cents_zero_in_divided():
    assert Amount(6, 0) / Amount(1, 50) == Amount(4, 0)
예제 #12
0
def test_set_maximum_debt_converts_dollars_and_cents_passed_to_amount(fake_account_repo, account_id):
    debit_account(UniqueID(), account_id, fake_account_repo, AmountDTO(132, 55))
    account_called_with: Account = fake_account_repo.save.call_args.args[0]
    maximum_debt_event: AccountMaximumDebtChanged = account_called_with.uncommitted_changes[-1]
    assert Amount(maximum_debt_event.dollars, maximum_debt_event.cents) == Amount(132, 55)
예제 #13
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
예제 #14
0
def test_if_cents_over_100_it_converts_to_dollars():
    amount = Amount(8, 253)
    assert amount.dollars == 10
    assert amount.cents == 53
예제 #15
0
def test_amount_immutable():
    amount = Amount(5, 12)
    with pytest.raises(FrozenInstanceError):
        amount.dollars = 4
예제 #16
0
def test_greater_if_first_has_less_dollars_more_cents():
    amount1 = Amount(1, 99)
    amount2 = Amount(43, 12)
    assert amount2 > amount1
예제 #17
0
def test_greater_if_first_has_more_dollars_and_less_cents():
    amount1 = Amount(9, 21)
    amount2 = Amount(2, 23)
    assert amount1 > amount2
예제 #18
0
def test_two_different_objects_different_amount_not_equal():
    amount1 = Amount(3, 1)
    amount2 = Amount(6, 32)
    assert amount1 != amount2
예제 #19
0
def test_two_different_objects_same_amount_are_equal():
    amount1 = Amount(5, 43)
    amount2 = Amount(5, 43)
    assert amount1 == amount2
예제 #20
0
def test_total_cents():
    assert Amount(9, 42).total_cents == 942
예제 #21
0
def test_total_dollars():
    assert Amount(4, 12).total_dollars == 4.12
예제 #22
0
def test_division_no_zeros():
    assert Amount(50, 80) / Amount(25, 40) == Amount(2, 0)
예제 #23
0
def test_division_by_zero_dollars_and_cents():
    with pytest.raises(ZeroDivisionError):
        Amount(12, 32) / Amount(0, 0)
예제 #24
0
def test_credit_account_converts_dollars_and_cents_passed_to_amount(fake_account_repo, account_id):
    credit_account(UniqueID(), account_id, fake_account_repo, AmountDTO(50, 24))
    account_called_with: Account = fake_account_repo.save.call_args.args[0]
    credit_event: AccountCredited = account_called_with.uncommitted_changes[-1]
    assert Amount(credit_event.dollars, credit_event.cents) == Amount(50, 24)
예제 #25
0
def test_negative_of_amount():
    assert -Amount(50, 24) == Amount(-50, -24)
예제 #26
0
def test_division_cents_zero_in_divider():
    assert Amount(10, 30) / Amount(2, 0) == Amount(5, 15)
예제 #27
0
def test_raises_value_error_when_dividing_by_negative_amount():
    assert Amount(12, 0) / Amount(-3, 0) == Amount(-4, 0)
예제 #28
0
def test_division_dollar_zero_in_divider():
    assert Amount(2, 50) / Amount(0, 10) == Amount(0, 25)
예제 #29
0
def test_amount_lower_than_logic():
    amount1 = Amount(1, 98)
    amount2 = Amount(6, 24)
    assert amount1 < amount2
예제 #30
0
def test_debit_account_converts_dollars_and_cents_passed_to_amount(fake_account_repo, account_id):
    debit_account(UniqueID(), account_id, fake_account_repo, AmountDTO(99, 12))
    account_called_with: Account = fake_account_repo.save.call_args.args[0]
    debit_event: AccountDebited = account_called_with.uncommitted_changes[-1]
    assert Amount(debit_event.dollars, debit_event.cents) == Amount(99, 12)