Beispiel #1
0
    async def test_derive_without_events(
            self, event_type_type: Type[DerivableEventType]):
        person = Person('P0')

        created, updated = derive(person, event_type_type)

        self.assertEquals(0, created)
        self.assertEquals(0, updated)
        self.assertEquals(0, len(person.presences))
Beispiel #2
0
    async def test_derive_create_derivable_events_without_reference_events(
            self, event_type_type: Type[DerivableEventType]):
        person = Person('P0')
        derivable_event = Event(None, Ignored())
        Presence(person, Subject(), derivable_event)

        created, updated = derive(person, event_type_type)

        self.assertEquals(0, created)
        self.assertEquals(0, updated)
        self.assertEquals(1, len(person.presences))
        self.assertIsNone(derivable_event.date)
Beispiel #3
0
    async def test_derive_update_comes_after_derivable_event(
            self, expected_datey: Optional[Datey],
            after_datey: Optional[Datey], derivable_datey: Optional[Datey]):
        expected_updates = 0 if expected_datey == derivable_datey else 1
        person = Person('P0')
        Presence(person, Subject(), Event(Ignored(), Date(0, 0, 0)))
        Presence(person, Subject(), Event(ComesAfterReference(), after_datey))
        derivable_event = Event(ComesAfterDerivable(), derivable_datey)
        Presence(person, Subject(), derivable_event)

        created, updated = derive(person, ComesAfterDerivable)

        self.assertEquals(expected_datey, derivable_event.date)
        self.assertEquals(0, created)
        self.assertEquals(expected_updates, updated)
        self.assertEquals(3, len(person.presences))
Beispiel #4
0
    async def test_derive_create_comes_after_derivable_event(
            self, expected_datey: Optional[Datey],
            after_datey: Optional[Datey]):
        expected_creations = 0 if expected_datey is None else 1
        person = Person('P0')
        Presence(person, Subject(), Event(Ignored(), Date(0, 0, 0)))
        Presence(person, Subject(), Event(ComesAfterReference(), after_datey))

        created, updated = derive(person, ComesAfterCreatableDerivable)

        derived_presences = [
            presence for presence in person.presences
            if isinstance(presence.event.type, ComesAfterCreatableDerivable)
        ]
        self.assertEquals(expected_creations, len(derived_presences))
        if expected_creations:
            derived_presence = derived_presences[0]
            self.assertIsInstance(derived_presence.role, Subject)
            self.assertEquals(expected_datey, derived_presence.event.date)
        self.assertEquals(expected_creations, created)
        self.assertEquals(0, updated)
        self.assertEquals(2 + expected_creations, len(person.presences))