Пример #1
0
def test_log_get_submissions(member, store0):
    submissions = Submission.objects.all()
    submission_log = Log()
    sub_events = submission_log.get_submission_events()
    unit0 = store0.units[0]
    unit0.source = "new source"
    unit0.save(user=member)
    lifecycle.get(unit0.__class__)(unit0).change()
    unit1 = store0.units[0]
    unit1.translator_comment = "new comment"
    unit1.save(user=member)
    lifecycle.get(unit1.__class__)(unit1).change()
    qc = store0.units.filter(
        qualitycheck__isnull=False)[0].qualitycheck_set.all()[0]
    lifecycle.get(qc.unit.__class__)(qc.unit).sub_mute_qc(
        submitter=member, quality_check=qc).save()
    assert type(sub_events).__name__ == "generator"
    assert len(list(sub_events)) == submissions.count()
    expected = submissions.filter(
        submitter=member).filter(
            unit__store=store0).in_bulk()
    result = submission_log.get_submission_events(
        store=store0.pk, users=[member])
    for event in result:
        sub = expected[event.value.pk]
        event_name = "state_changed"
        if sub.field == SubmissionFields.CHECK:
            event_name = (
                "check_muted"
                if sub.new_value == "0"
                else "check_unmuted")
        elif sub.field == SubmissionFields.TARGET:
            event_name = "target_updated"
        elif sub.field == SubmissionFields.SOURCE:
            event_name = "source_updated"
        elif sub.field == SubmissionFields.COMMENT:
            event_name = "comment_updated"
        assert isinstance(event, submission_log.event)
        assert event.unit == sub.unit
        assert event.user == sub.submitter
        assert event.timestamp == sub.creation_time
        assert event.action == event_name
        assert event.value == sub
        assert event.revision == sub.revision
Пример #2
0
def test_log_get_submissions(member, store0):
    submissions = Submission.objects.all()
    submission_log = Log()
    sub_events = submission_log.get_submission_events()
    unit0 = store0.units[0]
    unit0.source = "new source"
    unit0.save(user=member)
    lifecycle.get(unit0.__class__)(unit0).change()
    unit1 = store0.units[0]
    unit1.translator_comment = "new comment"
    unit1.save(user=member)
    lifecycle.get(unit1.__class__)(unit1).change()
    qc = store0.units.filter(
        qualitycheck__isnull=False)[0].qualitycheck_set.all()[0]
    lifecycle.get(qc.unit.__class__)(qc.unit).sub_mute_qc(
        submitter=member, quality_check=qc).save()
    assert type(sub_events).__name__ == "generator"
    assert len(list(sub_events)) == submissions.count()
    expected = submissions.filter(submitter=member).filter(
        unit__store=store0).in_bulk()
    result = submission_log.get_submission_events(store=store0.pk,
                                                  users=[member])
    for event in result:
        sub = expected[event.value.pk]
        event_name = "state_changed"
        if sub.field == SubmissionFields.CHECK:
            event_name = ("check_muted"
                          if sub.new_value == "0" else "check_unmuted")
        elif sub.field == SubmissionFields.TARGET:
            event_name = "target_updated"
        elif sub.field == SubmissionFields.SOURCE:
            event_name = "source_updated"
        elif sub.field == SubmissionFields.COMMENT:
            event_name = "comment_updated"
        assert isinstance(event, submission_log.event)
        assert event.unit == sub.unit
        assert event.user == sub.submitter
        assert event.timestamp == sub.creation_time
        assert event.action == event_name
        assert event.value == sub
        assert event.revision == sub.revision
Пример #3
0
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])
Пример #4
0
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])