def test_grouped_events(store_po): assert grouped_events.get(Log) == GroupedEvents units = [ ('Unit 0 Source', 'Unit 0 Target', False), ('Unit 1 Source', '', False), ('Unit 2 Source', 'Unit 2 Fuzzy Target', True), ] store_po.update(create_store(units=units)) units = [ ('Unit 0 Source', 'Unit 0 Target', False), ('Unit 1 Source', 'Unit 1 Target', False), ('Unit 2 Source', 'Unit 2 Target', False), ] store_po.update(create_store(units=units)) store_log = log.get(store_po.__class__)(store_po) expected = [ (x.unit, x.user, x.timestamp, x.action, x.value, x.old_value, x.revision) for x in sorted([ ComparableLogEvent(ev) for ev in store_log.get_events()])] result = [ (x.unit, x.user, x.timestamp, x.action, x.value, x.old_value, x.revision) for x in GroupedEvents(store_log).sorted_events()] assert expected == result
def test_log_store(store0): store_log = log.get(store0.__class__)(store0) assert isinstance(store_log, StoreLog) assert store_log.store == store0 assert all( x == store0.id for x in store_log.submissions.values_list( "unit__store_id", flat=True)) assert ( store_log.submissions.count() == Submission.objects.filter( unit__store_id=store0.id).count()) assert all( x == store0.id for x in store_log.suggestions.values_list( "unit__store_id", flat=True)) assert ( store_log.suggestions.count() == Suggestion.objects.filter( unit__store_id=store0.id).count()) assert ( store_log.created_units.count() == UnitSource.objects.filter( unit__store_id=store0.id).count()) assert all( x == store0.id for x in store_log.created_units.values_list( "unit__store_id", flat=True)) subs = store_log.submissions assert ( store_log.filter_store(subs, store=store0.id) == subs)
def test_user_log(admin): user_log = log.get(admin.__class__)(admin) assert isinstance(user_log, UserLog) assert list(user_log.get_events()) suggestions = admin.suggestions.all() | admin.reviews.all() assert (list(user_log.suggestion_qs.values_list("pk", flat=True)) == list( suggestions.values_list("pk", flat=True))) assert (list(user_log.submission_qs.values_list("pk", flat=True)) == list( admin.submission_set.values_list("pk", flat=True)))
def test_user_log(admin): user_log = log.get(admin.__class__)(admin) assert isinstance(user_log, UserLog) assert list(user_log.get_events()) suggestions = admin.suggestions.all() | admin.reviews.all() assert ( list(user_log.suggestion_qs.values_list("pk", flat=True)) == list(suggestions.values_list("pk", flat=True))) assert ( list(user_log.submission_qs.values_list("pk", flat=True)) == list(admin.submission_set.values_list("pk", flat=True)))
def test_log_unit(store0): unit = store0.units.filter(state=TRANSLATED).first() unit_log = log.get(unit.__class__)(unit) assert isinstance(unit_log, UnitLog) assert unit_log.unit == unit assert all(x == unit.id for x in unit_log.submissions.values_list("unit_id", flat=True)) assert (unit_log.submissions.count() == Submission.objects.filter( unit_id=unit.id).count()) assert all(x == unit.id for x in unit_log.suggestions.values_list("unit_id", flat=True)) assert (unit_log.suggestions.count() == Suggestion.objects.filter( unit_id=unit.id).count()) assert (unit_log.created_units.count() == UnitSource.objects.filter( unit_id=unit.id).count()) assert all( x == unit.id for x in unit_log.created_units.values_list("unit_id", flat=True)) subs = unit_log.submissions assert (unit_log.filter_store(subs, store=unit.store.id) == subs)
def test_log_store(store0): store_log = log.get(store0.__class__)(store0) assert isinstance(store_log, StoreLog) assert store_log.store == store0 assert all(x == store0.id for x in store_log.submissions.values_list("unit__store_id", flat=True)) assert (store_log.submissions.count() == Submission.objects.filter( unit__store_id=store0.id).count()) assert all(x == store0.id for x in store_log.suggestions.values_list("unit__store_id", flat=True)) assert (store_log.suggestions.count() == Suggestion.objects.filter( unit__store_id=store0.id).count()) assert (store_log.created_units.count() == UnitSource.objects.filter( unit__store_id=store0.id).count()) assert all(x == store0.id for x in store_log.created_units.values_list("unit__store_id", flat=True)) subs = store_log.submissions assert (store_log.filter_store(subs, store=store0.id) == subs)
def test_log_unit(store0): unit = store0.units.filter(state=TRANSLATED).first() unit_log = log.get(unit.__class__)(unit) assert isinstance(unit_log, UnitLog) assert unit_log.unit == unit assert all( x == unit.id for x in unit_log.submissions.values_list( "unit_id", flat=True)) assert ( unit_log.submissions.count() == Submission.objects.filter( unit_id=unit.id).count()) assert all( x == unit.id for x in unit_log.suggestions.values_list( "unit_id", flat=True)) assert ( unit_log.suggestions.count() == Suggestion.objects.filter( unit_id=unit.id).count()) assert ( unit_log.created_units.count() == UnitSource.objects.filter( unit_id=unit.id).count()) assert all( x == unit.id for x in unit_log.created_units.values_list( "unit_id", flat=True)) subs = unit_log.submissions assert ( unit_log.filter_store(subs, store=unit.store.id) == subs)
def test_grouped_events(store_po): assert grouped_events.get(Log) == GroupedEvents units = [ ('Unit 0 Source', 'Unit 0 Target', False), ('Unit 1 Source', '', False), ('Unit 2 Source', 'Unit 2 Fuzzy Target', True), ] store_po.update(create_store(units=units)) units = [ ('Unit 0 Source', 'Unit 0 Target', False), ('Unit 1 Source', 'Unit 1 Target', False), ('Unit 2 Source', 'Unit 2 Target', False), ] store_po.update(create_store(units=units)) store_log = log.get(store_po.__class__)(store_po) expected = [(x.unit, x.user, x.timestamp, x.action, x.value, x.old_value, x.revision) for x in sorted( [ComparableLogEvent(ev) for ev in store_log.get_events()])] result = [(x.unit, x.user, x.timestamp, x.action, x.value, x.old_value, x.revision) for x in GroupedEvents(store_log).sorted_events()] assert expected == result
def logs(self): return log.get(self.context.__class__)(self.context)
def log(self): return log.get(self.user.__class__)(self.user)
def test_comparable_log(member, store0, store_po): assert comparable_event.get(Log) == ComparableLogEvent start = timezone.now().replace(microsecond=0) unit = store0.units.filter(state=TRANSLATED).first() unit.target += 'UPDATED IN TEST' unit.save(user=member) unit = store0.units.filter(state=TRANSLATED).first() unit.target += 'UPDATED IN TEST AGAIN' unit.save(user=member) unit_log = log.get(unit.__class__)(unit) event1, event2 = [ComparableLogEvent(x) for x in unit_log.get_events(users=[member.id], start=start)] assert (event1 < event2) == (event1.revision < event2.revision) assert (event2 < event1) == (event2.revision < event1.revision) unit = store0.units.filter(state=UNTRANSLATED).first() sugg1, created_ = review.get(Suggestion)().add( unit, unit.source_f + 'SUGGESTION', user=member) sugg2, created_ = review.get(Suggestion)().add( unit, unit.source_f + 'SUGGESTION AGAIN', user=member) Suggestion.objects.filter(id=sugg2.id).update(creation_time=sugg1.creation_time) unit_log = log.get(unit.__class__)(unit) event1, event2 = [ComparableLogEvent(x) for x in unit_log.get_events(users=[member.id], start=start)] assert (event1 < event2) == (event1.value.pk < event2.value.pk) assert (event2 < event1) == (event2.value.pk < event1.value.pk) Suggestion.objects.filter(id=sugg2.id).update(creation_time=None) sugg2 = Suggestion.objects.get(id=sugg2.id) event1 = [ComparableLogEvent(x) for x in unit_log.get_events(users=[member.id], start=start)][0] event2 = ComparableLogEvent(unit_log.event(sugg2.unit, sugg2.user, sugg2.creation_time, "suggestion_created", sugg2)) assert event2 < event1 assert not (event1 < event2) units = [ ('Unit 0 Source', 'Unit 0 Target', False), ('Unit 1 Source', '', False), ] store_po.update(create_store(units=units)) unit1, unit2 = store_po.units unit2.__class__.objects.filter(id=unit2.id).update( creation_time=unit1.creation_time) store_log = log.get(store_po.__class__)(store_po) event1, event2 = [ComparableLogEvent(x) for x in store_log.get_events()] assert (event1 < event2) == (event1.unit.id < event2.unit.id) assert (event2 < event1) == (event2.unit.id < event1.unit.id) creation_time = unit1.creation_time + timedelta(seconds=1) unit2.__class__.objects.filter(id=unit2.id).update(creation_time=creation_time) event1, event2 = [ComparableLogEvent(x) for x in store_log.get_events()] assert (event1 < event2) == (event1.timestamp < event2.timestamp) assert (event2 < event1) == (event2.timestamp < event1.timestamp) unit = store_po.units.filter(state=UNTRANSLATED)[0] unit.target = 'Unit 1 Target' unit.save() unit_log = log.get(unit.__class__)(unit) event1, event2 = [ComparableLogEvent(x) for x in unit_log.get_submission_events()] assert not (event1 < event2) and not (event2 < event1)
def test_comparable_log(member, store0, store_po): assert comparable_event.get(Log) == ComparableLogEvent start = timezone.now().replace(microsecond=0) unit = store0.units.filter(state=TRANSLATED).first() unit.target += 'UPDATED IN TEST' unit.save(user=member) unit = store0.units.filter(state=TRANSLATED).first() unit.target += 'UPDATED IN TEST AGAIN' unit.save(user=member) unit_log = log.get(unit.__class__)(unit) event1, event2 = [ ComparableLogEvent(x) for x in unit_log.get_events(users=[member.id], start=start) ] assert (event1 < event2) == (event1.revision < event2.revision) assert (event2 < event1) == (event2.revision < event1.revision) unit = store0.units.filter(state=UNTRANSLATED).first() sugg1, created_ = review.get(Suggestion)().add(unit, unit.source_f + 'SUGGESTION', user=member) sugg2, created_ = review.get(Suggestion)().add(unit, unit.source_f + 'SUGGESTION AGAIN', user=member) Suggestion.objects.filter(id=sugg2.id).update( creation_time=sugg1.creation_time) unit_log = log.get(unit.__class__)(unit) event1, event2 = [ ComparableLogEvent(x) for x in unit_log.get_events(users=[member.id], start=start) ] assert (event1 < event2) == (event1.value.pk < event2.value.pk) assert (event2 < event1) == (event2.value.pk < event1.value.pk) Suggestion.objects.filter(id=sugg2.id).update(creation_time=None) sugg2 = Suggestion.objects.get(id=sugg2.id) event1 = [ ComparableLogEvent(x) for x in unit_log.get_events(users=[member.id], start=start) ][0] event2 = ComparableLogEvent( unit_log.event(sugg2.unit, sugg2.user, sugg2.creation_time, "suggestion_created", sugg2)) assert event2 < event1 assert not (event1 < event2) units = [ ('Unit 0 Source', 'Unit 0 Target', False), ('Unit 1 Source', '', False), ] store_po.update(create_store(units=units)) unit1, unit2 = store_po.units unit2.__class__.objects.filter(id=unit2.id).update( creation_time=unit1.creation_time) store_log = log.get(store_po.__class__)(store_po) event1, event2 = [ComparableLogEvent(x) for x in store_log.get_events()] assert (event1 < event2) == (event1.unit.id < event2.unit.id) assert (event2 < event1) == (event2.unit.id < event1.unit.id) creation_time = unit1.creation_time + timedelta(seconds=1) unit2.__class__.objects.filter(id=unit2.id).update( creation_time=creation_time) event1, event2 = [ComparableLogEvent(x) for x in store_log.get_events()] assert (event1 < event2) == (event1.timestamp < event2.timestamp) assert (event2 < event1) == (event2.timestamp < event1.timestamp) unit = store_po.units.filter(state=UNTRANSLATED)[0] unit.target = 'Unit 1 Target' unit.save() unit_log = log.get(unit.__class__)(unit) event1, event2 = [ ComparableLogEvent(x) for x in unit_log.get_submission_events() ] assert not (event1 < event2) and not (event2 < event1)