def test_log_get_created_units(system, store0): created_units = UnitSource.objects.all() created_unit_log = Log() created = created_unit_log.get_created_unit_events(include_meta=True) assert type(created).__name__ == "generator" assert len(list(created)) == created_units.count() expected = created_units.filter(created_by=system).filter( unit__store=store0).in_bulk() result = created_unit_log.get_created_unit_events(store=store0.pk, users=[system]) for event in result: created_unit = expected[event.value.pk] assert isinstance(event, created_unit_log.event) assert event.unit == created_unit.unit assert event.user == created_unit.created_by assert event.timestamp == created_unit.unit.creation_time assert event.action == "unit_created" assert event.value == created_unit
def test_log_get_created_units(system, store0): created_units = UnitSource.objects.all() created_unit_log = Log() created = created_unit_log.get_created_unit_events( include_meta=True) assert type(created).__name__ == "generator" assert len(list(created)) == created_units.count() expected = created_units.filter( created_by=system).filter( unit__store=store0).in_bulk() result = created_unit_log.get_created_unit_events( store=store0.pk, users=[system]) for event in result: created_unit = expected[event.value.pk] assert isinstance(event, created_unit_log.event) assert event.unit == created_unit.unit assert event.user == created_unit.created_by assert event.timestamp == created_unit.unit.creation_time assert event.action == "unit_created" assert event.value == created_unit
def test_log_get_events(site_users, store0): user = site_users["user"] event_log = Log() kwargs = dict(users=[user], store=store0) result = sorted(event_log.get_events(**kwargs), key=(lambda ev: (ev.timestamp, ev.unit.pk))) expected = sorted(list(event_log.get_created_unit_events(**kwargs)) + list(event_log.get_suggestion_events(**kwargs)) + list(event_log.get_submission_events(**kwargs)), key=(lambda ev: (ev.timestamp, ev.unit.pk))) assert ([(x.timestamp, x.unit, x.action) for x in result ] == [(x.timestamp, x.unit, x.action) for x in expected])
def test_log_get_events(site_users, store0): user = site_users["user"] event_log = Log() kwargs = dict(users=[user], store=store0) result = sorted( event_log.get_events(**kwargs), key=(lambda ev: (ev.timestamp, ev.unit.pk))) expected = sorted( list(event_log.get_created_unit_events(**kwargs)) + list(event_log.get_suggestion_events(**kwargs)) + list(event_log.get_submission_events(**kwargs)), key=(lambda ev: (ev.timestamp, ev.unit.pk))) assert ( [(x.timestamp, x.unit, x.action) for x in result] == [(x.timestamp, x.unit, x.action) for x in expected])