def test_validate_aggregate_events(self): event1 = AggregateRoot.Created( originator_version=0, originator_id='1', originator_topic=get_topic(AggregateRoot)) event1.__check_hash__() # Chain another event. event2 = AggregateRoot.AttributeChanged( originator_version=1, originator_id='1', __previous_hash__=event1.__event_hash__) event2.__check_hash__() # Chain another event. event3 = AggregateRoot.AttributeChanged( originator_version=2, originator_id='1', __previous_hash__=event2.__event_hash__) event3.__check_hash__()
def test_event_hash_error(self): event1 = AggregateRoot.Created( originator_version=0, originator_id='1', originator_topic=get_topic(AggregateRoot)) event1.__check_hash__() # Break the hash. event1.__dict__['event_hash'] = 'damage' with self.assertRaises(EventHashError): event1.__check_hash__()
def example_policy(repository, event): if isinstance(event, ExampleAggregate.Created): # Create a second aggregate, allowing test to check that # events from more than one entity are stored. second_id = uuid4() second = AggregateRoot.__create__(originator_id=second_id) # Get first aggregate and move it on, allowing test to # check that the first aggregate was mutated by the policy. first = repository[event.originator_id] assert isinstance(first, ExampleAggregate) first.move_on(second_id=second_id) return second elif isinstance(event, Command.Created): command_class = resolve_topic(event.originator_topic) if command_class is CreateExample: return ExampleAggregate.__create__(event.example_id)
def example_policy(repository, event): # Whenever an aggregate is created, then "move it on". if isinstance(event, ExampleAggregate.Created): # Get aggregate and move it on. aggregate = repository[event.originator_id] assert isinstance(aggregate, ExampleAggregate) # Also create a second entity, allows test to check that # events from more than one entity are stored. second_id = uuid4() other_entity = AggregateRoot.__create__(originator_id=second_id) aggregate.move_on(second_id=second_id) return other_entity elif isinstance(event, Command.Created): command_class = resolve_topic(event.originator_topic) if command_class is CreateExample: return ExampleAggregate.__create__()
def policy(repository, event): first = AggregateRoot.__create__(originator_id=(uuid4())) second = AggregateRoot.__create__(originator_id=(uuid4())) return (first, second)