def test_initialize_sets_uncommitted_changes(): aggregate = applyless_aggregate() aggregate._initialize([ BaseEvent(operation_id=str(UniqueID())), BaseEvent(operation_id=str(UniqueID())) ]) assert len(aggregate.uncommitted_changes) == 2
def test_apply_event_is_called_for_each_event_passed_when_loading_aggregate(): with patch.object(AggregateRoot, 'apply_event') as mock: AggregateRoot( EventStream([ BaseEvent(operation_id=str(UniqueID())), BaseEvent(operation_id=str(UniqueID())), BaseEvent(operation_id=str(UniqueID())) ])) assert mock.call_count == 3
def test_marking_changes_as_committed_adds_committed_events_operation_ids_to_committed_operations( ): aggregate = applyless_aggregate() event1 = BaseEvent(operation_id=str(UniqueID())) event2 = BaseEvent(operation_id=str(UniqueID())) aggregate.apply_event(event1) aggregate.apply_event(event2) aggregate.mark_changes_as_committed() assert event1.operation_id in aggregate.committed_operations assert event2.operation_id in aggregate.committed_operations
def test_applying_new_event_with_same_operation_id_as_already_committed_event_raises_app_exception( ): aggregate = applyless_aggregate() operation_id = UniqueID() event1 = BaseEvent(operation_id=operation_id.value) event2 = BaseEvent(operation_id=operation_id.value) aggregate.apply_event(event1) aggregate.mark_changes_as_committed() with pytest.raises(OperationDuplicate): aggregate.apply_event(event2)
def test_event_construct_from_dict(): BaseEvent(**{'version': 1, 'operation_id': 'fdsf'})
def test_event_default_version_is_one(): assert BaseEvent(operation_id='asd').version == 1
def test_event_is_key_word_only(): with pytest.raises(TypeError): BaseEvent('operation') with pytest.raises(TypeError): BaseEvent('operation', version=3)
def test_event_construct_from_dict_changes_version(): event = BaseEvent(**{'version': 4, 'operation_id': 'fdsf'}) assert event.version == 4
def test_applying_new_events_does_not_add_operation_id_to_operations_committed( ): event1 = BaseEvent(operation_id=str(UniqueID())) aggregate = applyless_aggregate() aggregate.apply_event(event1) assert event1.operation_id not in aggregate.committed_operations
def test_loading_aggregate_adds_each_operation_id_to_operations_committed_with_value_of_true( ): event1 = BaseEvent(operation_id=str(UniqueID())) aggregate = AggregateRoot(EventStream([event1])) assert event1.operation_id in aggregate.committed_operations assert aggregate.committed_operations[event1.operation_id] is True
def test_applying_new_event_adds_it_to_uncommitted_changes(): aggregate = applyless_aggregate() event = BaseEvent(operation_id=str(UniqueID())) aggregate.apply_event(event) assert aggregate.uncommitted_changes[-1] == event
def test_initialize_sets_changes(): aggregate = applyless_aggregate() operation_id = UniqueID() aggregate._initialize([BaseEvent(operation_id=str(operation_id))]) assert aggregate.uncommitted_changes[0].operation_id == str(operation_id)