Exemplo n.º 1
0
    def test_event_mutate_raises_version_error(self):
        a = Aggregate()

        # Try to mutate aggregate with an invalid domain event.
        event = AggregateEvent(
            originator_id=a.id,
            originator_version=a.version,  # NB not +1.
            timestamp=datetime.now(tz=TZINFO),
        )
        # Check raises "VersionError".
        with self.assertRaises(VersionError):
            event.mutate(a)
Exemplo n.º 2
0
    def test_event_mutate_raises_originator_id_error(self):
        a = Aggregate()

        # Try to mutate aggregate with an invalid domain event.
        event = AggregateEvent(
            originator_id=uuid4(),
            originator_version=a.version + 1,
            timestamp=AggregateEvent.create_timestamp(),
        )
        # Check raises "VersionError".
        with self.assertRaises(OriginatorIDError):
            event.mutate(a)
Exemplo n.º 3
0
    def test(self):

        # Define fixture that receives prompts.
        class FollowerFixture(Promptable):
            def __init__(self):
                self.num_prompts = 0

            def receive_prompt(self, leader_name: str) -> None:
                self.num_prompts += 1

        # Test fixture is working.
        follower = FollowerFixture()
        follower.receive_prompt("")
        self.assertEqual(follower.num_prompts, 1)

        # Construct leader.
        leader = Leader()
        leader.lead(follower)

        # Check follower receives a prompt when there are new events.
        leader.notify([
            AggregateEvent(
                originator_id=uuid4(),
                originator_version=0,
                timestamp=datetime.now(),
            )
        ])
        self.assertEqual(follower.num_prompts, 2)

        # Check follower doesn't receive prompt when no new events.
        leader.notify([])
        self.assertEqual(follower.num_prompts, 2)