Exemple #1
0
def test_log_filter_store(store0):
    subs = Submission.objects.all()
    suggestions = Suggestion.objects.all()
    unit_sources = UnitSource.objects.all()
    for qs in [subs, suggestions, unit_sources]:
        assert (list(Log().filter_store(qs, store0.pk)) == list(
            qs.filter(unit__store=store0)))
        # None should return original qs
        assert (Log().filter_store(qs, None) == qs)
Exemple #2
0
def test_log_filter_path(tp0, store0):
    subs = Submission.objects.all()
    suggestions = Suggestion.objects.all()
    unit_sources = UnitSource.objects.all()
    for path in [tp0.pootle_path, store0.pootle_path]:
        for qs in [subs, suggestions, unit_sources]:
            assert (list(Log().filter_path(qs, path)) == list(
                qs.filter(unit__store__pootle_path__startswith=path)))
            # None should return original qs
            assert Log().filter_path(qs, None) == qs
Exemple #3
0
def test_log_filtered_submissions(member, tp0, store0):
    subs = Submission.objects.all()
    sub_start, sub_end = _get_mid_times(subs)
    sub_log = Log()
    # no filtering
    assert (sub_log.filtered_submissions().count() ==
            sub_log.submissions.count() == subs.count())
    user_subs = (sub_log.filter_users(sub_log.submissions, users=[member]))
    assert user_subs.count()
    assert (list(user_subs) == list(
        sub_log.filtered_submissions(users=[member])))
    time_subs = (sub_log.filter_timestamps(sub_log.submissions,
                                           start=sub_start,
                                           end=sub_end))
    assert time_subs.count()
    assert (list(time_subs) == list(
        sub_log.filtered_submissions(start=sub_start, end=sub_end)))
    store_subs = (sub_log.filter_store(sub_log.submissions, store0.pk))
    assert store_subs.count()
    assert (list(sub_log.submissions.filter(
        unit__store_id=store0.pk)) == list(store_subs))
    path_subs = (sub_log.filter_path(sub_log.submissions, tp0.pootle_path))
    assert path_subs.count()
    assert (sub_log.submissions.filter(
        unit__store__pootle_path__startswith=tp0.pootle_path).count() ==
            path_subs.count())
Exemple #4
0
def test_log_filter_sugg_timestamps(member):
    suggs = Suggestion.objects.all()
    sugg_start, sugg_end = _get_mid_times(suggs)
    assert (list(Log().filter_timestamps(suggs, start=sugg_start)) == list(
        suggs.filter(creation_time__gte=sugg_start)))
    assert (list(Log().filter_timestamps(suggs, end=sugg_end)) == list(
        suggs.filter(creation_time__lt=sugg_end)))
    assert (list(Log().filter_timestamps(
        suggs, start=sugg_start, end=sugg_end)) == list(
            suggs.filter(creation_time__lt=sugg_end).filter(
                creation_time__gte=sugg_start)))
    # None should return original qs
    assert Log().filter_timestamps(suggs, start=None, end=None) == suggs
Exemple #5
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])
Exemple #6
0
def test_log_filtered_created_units(system, tp0, store0):
    created_units = UnitSource.objects.all()
    created_unit_start, created_unit_end = _get_mid_times(
        created_units, field="unit__creation_time")
    created_unit_log = Log()
    # no filtering
    assert (
        created_unit_log.filtered_created_units(include_meta=True).count()
        == created_unit_log.created_units.count()
        == created_units.count())
    user_created_units = created_unit_log.filter_users(
        created_unit_log.created_units,
        [system.id],
        field="created_by_id",
        include_meta=True)
    assert user_created_units.count()
    assert (
        list(user_created_units)
        == list(created_unit_log.filtered_created_units(
            users=[system])))
    # using start and end seems to create empty - so only testing start
    time_created_units = created_unit_log.filter_timestamps(
        created_unit_log.created_units,
        start=created_unit_start,
        field="unit__creation_time")
    assert time_created_units.count()
    assert (
        list(time_created_units)
        == list(created_unit_log.filtered_created_units(
            start=created_unit_start, include_meta=True)))
    store_created_units = created_unit_log.filter_store(
        created_unit_log.created_units,
        store0.pk)
    assert store_created_units.count()
    assert (
        list(created_unit_log.filtered_created_units(
            store=store0.pk, include_meta=True))
        == list(store_created_units))
    path_created_units = created_unit_log.filter_path(
        created_unit_log.created_units,
        tp0.pootle_path)
    assert path_created_units.count()
    assert (
        created_unit_log.filtered_created_units(
            path=tp0.pootle_path, include_meta=True).count()
        == path_created_units.count())
Exemple #7
0
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
Exemple #8
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
Exemple #9
0
def test_log_filter_users(member):
    subs = Submission.objects.all()
    suggestions = Suggestion.objects.all()
    unit_sources = UnitSource.objects.all()
    assert (list(Log().filter_users(subs, [member.id])) == list(
        subs.filter(submitter=member)))
    assert (list(Log().filter_users(suggestions, [member.id],
                                    field="user_id")) == list(
                                        suggestions.filter(user=member)))
    assert (list(Log().filter_users(suggestions, [member.id],
                                    field="reviewer_id")) == list(
                                        suggestions.filter(reviewer=member)))
    assert (list(Log().filter_users(
        unit_sources, [member.id], field="created_by_id")) == list(
            unit_sources.filter(created_by=member)))
    # None should filter system users
    assert (list(Log().filter_users(
        unit_sources, None, field="created_by_id")) == list(
            unit_sources.exclude(
                created_by__username__in=get_user_model().objects.META_USERS)))
    # or return original qs otherwise
    assert (Log().filter_users(unit_sources,
                               None,
                               field="created_by_id",
                               include_meta=True) == unit_sources)
    # None should filter system users
    assert (list(Log().filter_users(
        suggestions, None, field="user_id")) == list(
            suggestions.exclude(
                user__username__in=get_user_model().objects.META_USERS)))
    # or return original qs otherwise
    assert (Log().filter_users(suggestions,
                               None,
                               field="user_id",
                               include_meta=True) == suggestions)
    # None should filter system users
    assert (list(Log().filter_users(subs, None, field="submitter_id")) == list(
        subs.exclude(
            submitter__username__in=get_user_model().objects.META_USERS)))
    # or return original qs otherwise
    assert (Log().filter_users(subs,
                               None,
                               field="submitter_id",
                               include_meta=True) == subs)
Exemple #10
0
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
Exemple #11
0
def test_log_base():
    base_log = Log()
    assert base_log.event == LogEvent
    assert (base_log.subtypes == {
        getattr(SubmissionTypes, n): n.lower()
        for n in ["WEB", "UPLOAD", "SYSTEM"]
    })
    assert (base_log.subfields == {
        getattr(SubmissionFields, n): n.lower()
        for n in ["SOURCE", "TARGET", "STATE", "COMMENT", "CHECK"]
    })
Exemple #12
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
Exemple #13
0
def test_log_filter_unit_create_timestamps(member):
    unit_creates = UnitSource.objects.all()
    unit_create_start, unit_create_end = _get_mid_times(
        unit_creates, field="unit__creation_time")
    assert (list(Log().filter_timestamps(
        unit_creates, start=unit_create_start,
        field="unit__creation_time")) == list(
            unit_creates.filter(unit__creation_time__gte=unit_create_start)))
    assert (list(Log().filter_timestamps(
        unit_creates, end=unit_create_end,
        field="unit__creation_time")) == list(
            unit_creates.filter(unit__creation_time__lt=unit_create_end)))
    assert (list(Log().filter_timestamps(
        unit_creates,
        start=unit_create_start,
        end=unit_create_end,
        field="unit__creation_time")) == list(
            unit_creates.filter(
                unit__creation_time__lt=unit_create_end).filter(
                    unit__creation_time__gte=unit_create_start)))
    # None should return original qs
    assert (Log().filter_timestamps(
        unit_creates, start=None, end=None,
        field="unit__creation_time") == unit_creates)
Exemple #14
0
def test_log_filtered_submissions(member, tp0, store0):
    subs = Submission.objects.all()
    sub_start, sub_end = _get_mid_times(subs)
    sub_log = Log()
    # no filtering
    assert (
        sub_log.filtered_submissions().count()
        == sub_log.submissions.count()
        == subs.count())
    user_subs = (
        sub_log.filter_users(
            sub_log.submissions,
            users=[member]))
    assert user_subs.count()
    assert (
        list(user_subs)
        == list(sub_log.filtered_submissions(users=[member])))
    time_subs = (
        sub_log.filter_timestamps(
            sub_log.submissions,
            start=sub_start,
            end=sub_end))
    assert time_subs.count()
    assert (
        list(time_subs)
        == list(sub_log.filtered_submissions(
            start=sub_start, end=sub_end)))
    store_subs = (
        sub_log.filter_store(
            sub_log.submissions,
            store0.pk))
    assert store_subs.count()
    assert (
        list(sub_log.submissions.filter(unit__store_id=store0.pk))
        == list(store_subs))
    path_subs = (
        sub_log.filter_path(
            sub_log.submissions,
            tp0.pootle_path))
    assert path_subs.count()
    assert (
        sub_log.submissions.filter(
            unit__store__pootle_path__startswith=tp0.pootle_path).count()
        == path_subs.count())
Exemple #15
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])
Exemple #16
0
def test_log_get_suggestions(member, store0):
    suggestions = Suggestion.objects.all()
    sugg_start, sugg_end = _get_mid_times(suggestions)
    sugg_log = Log()
    sugg_events = sugg_log.get_suggestion_events()
    assert type(sugg_events).__name__ == "generator"
    user_time_suggestions = (
        (sugg_log.filter_users(
            sugg_log.suggestions,
            [member],
            field="user_id")
         & sugg_log.filter_timestamps(
             sugg_log.suggestions,
             start=sugg_start,
             end=sugg_end))
        | (sugg_log.filter_users(
            sugg_log.suggestions,
            [member],
            field="reviewer_id")
           & sugg_log.filter_timestamps(
               sugg_log.suggestions,
               start=sugg_start,
               end=sugg_end,
               field="review_time")))
    assert user_time_suggestions
    pending = suggestions.filter(
        creation_time__gte=sugg_start,
        creation_time__lt=sugg_end,
        state__name="pending").first()
    review.get(Suggestion)([pending], member).accept()
    pending = suggestions.filter(
        creation_time__gte=sugg_start,
        creation_time__lt=sugg_end,
        state__name="pending").first()
    review.get(Suggestion)([pending], member).reject()
    pending.review_time = sugg_start
    pending.save()
    expected = {}
    for suggestion in user_time_suggestions.all():
        add_event = (
            (suggestion.creation_time >= sugg_start)
            and (suggestion.creation_time < sugg_end)
            and (suggestion.user == member))
        review_event = (
            (suggestion.review_time >= sugg_start)
            and (suggestion.review_time < sugg_end)
            and (suggestion.reviewer == member))
        expected[suggestion.id] = {}
        if add_event:
            expected[suggestion.id]["suggestion_created"] = (
                sugg_log.event(
                    suggestion.unit,
                    suggestion.user,
                    suggestion.creation_time,
                    "suggestion_created",
                    suggestion))
        if review_event:
            event_name = (
                "suggestion_accepted"
                if suggestion.state.name == "accepted"
                else "suggestion_rejected")
            expected[suggestion.id][event_name] = (
                sugg_log.event(
                    suggestion.unit,
                    suggestion.reviewer,
                    suggestion.review_time,
                    event_name,
                    suggestion))
    result = sugg_log.get_suggestion_events(
        start=sugg_start, end=sugg_end, users=[member.id])
    for event in result:
        assert isinstance(event, sugg_log.event)
        sugg_review = expected[event.value.pk][event.action]
        assert event.unit == sugg_review.unit
        assert event.action in [
            "suggestion_created", "suggestion_accepted", "suggestion_rejected"]
        assert event.user == (
            sugg_review.value.user
            if event.action == "suggestion_created"
            else sugg_review.value.reviewer)
        assert event.timestamp == (
            sugg_review.value.creation_time
            if event.action == "suggestion_created"
            else sugg_review.value.review_time)
        assert event.value == sugg_review.value
Exemple #17
0
def test_log_filtered_suggestions(member, tp0, store0):
    suggs = Suggestion.objects.all()
    sugg_start, sugg_end = _get_mid_times(suggs)
    sugg_log = Log()
    # no filtering
    assert (
        sugg_log.filtered_suggestions().count()
        == sugg_log.suggestions.count()
        == suggs.count())
    user_suggestions = (
        sugg_log.filter_users(
            sugg_log.suggestions,
            [member],
            field="user_id")
        | sugg_log.filter_users(
            sugg_log.suggestions,
            [member],
            field="reviewer_id"))
    assert user_suggestions
    assert (
        list(user_suggestions.order_by("id"))
        == list(sugg_log.filtered_suggestions(
            users=[member]).order_by("id")))
    time_suggestions = (
        sugg_log.filter_timestamps(
            sugg_log.suggestions,
            start=sugg_start,
            end=sugg_end)
        | sugg_log.filter_timestamps(
            sugg_log.suggestions,
            start=sugg_start,
            end=sugg_end,
            field="review_time"))
    assert time_suggestions
    assert (
        list(time_suggestions.order_by("id"))
        == list(sugg_log.filtered_suggestions(
            start=sugg_start, end=sugg_end).order_by("id")))
    user_time_suggestions = (
        (sugg_log.filter_users(
            sugg_log.suggestions,
            [member],
            field="user_id")
         & sugg_log.filter_timestamps(
             sugg_log.suggestions,
             start=sugg_start,
             end=sugg_end))
        | (sugg_log.filter_users(
            sugg_log.suggestions,
            [member],
            field="reviewer_id")
           & sugg_log.filter_timestamps(
               sugg_log.suggestions,
               start=sugg_start,
               end=sugg_end,
               field="review_time")))
    assert user_time_suggestions
    assert (
        list(user_time_suggestions.order_by("id"))
        == list(sugg_log.filtered_suggestions(
            start=sugg_start, end=sugg_end, users=[member]).order_by("id")))
    store_suggestions = sugg_log.filter_store(
        sugg_log.suggestions, store0.pk)
    assert store_suggestions
    assert (
        list(store_suggestions.order_by("id"))
        == list(sugg_log.filtered_suggestions(
            store=store0.id).order_by("id")))
    path_suggestions = sugg_log.filter_path(
        sugg_log.suggestions, tp0.pootle_path)
    assert path_suggestions.count()
    assert (
        path_suggestions.count()
        == sugg_log.filtered_suggestions(path=tp0.pootle_path).count())
Exemple #18
0
def test_log_filtered_suggestions(member, tp0, store0):
    suggs = Suggestion.objects.all()
    sugg_start, sugg_end = _get_mid_times(suggs)
    sugg_log = Log()
    # no filtering
    assert (sugg_log.filtered_suggestions().count() ==
            sugg_log.suggestions.count() == suggs.count())
    user_suggestions = (sugg_log.filter_users(sugg_log.suggestions, [member],
                                              field="user_id")
                        | sugg_log.filter_users(sugg_log.suggestions, [member],
                                                field="reviewer_id"))
    assert user_suggestions
    assert (list(user_suggestions.order_by("id")) == list(
        sugg_log.filtered_suggestions(users=[member]).order_by("id")))
    time_suggestions = (sugg_log.filter_timestamps(
        sugg_log.suggestions, start=sugg_start, end=sugg_end)
                        | sugg_log.filter_timestamps(sugg_log.suggestions,
                                                     start=sugg_start,
                                                     end=sugg_end,
                                                     field="review_time"))
    assert time_suggestions
    assert (list(time_suggestions.order_by("id")) == list(
        sugg_log.filtered_suggestions(start=sugg_start,
                                      end=sugg_end).order_by("id")))
    user_time_suggestions = (
        (sugg_log.filter_users(sugg_log.suggestions, [member], field="user_id")
         & sugg_log.filter_timestamps(
             sugg_log.suggestions, start=sugg_start, end=sugg_end))
        | (sugg_log.filter_users(sugg_log.suggestions, [member],
                                 field="reviewer_id")
           & sugg_log.filter_timestamps(sugg_log.suggestions,
                                        start=sugg_start,
                                        end=sugg_end,
                                        field="review_time")))
    assert user_time_suggestions
    assert (list(user_time_suggestions.order_by("id")) == list(
        sugg_log.filtered_suggestions(start=sugg_start,
                                      end=sugg_end,
                                      users=[member]).order_by("id")))
    store_suggestions = sugg_log.filter_store(sugg_log.suggestions, store0.pk)
    assert store_suggestions
    assert (list(store_suggestions.order_by("id")) == list(
        sugg_log.filtered_suggestions(store=store0.id).order_by("id")))
    path_suggestions = sugg_log.filter_path(sugg_log.suggestions,
                                            tp0.pootle_path)
    assert path_suggestions.count()
    assert (path_suggestions.count() == sugg_log.filtered_suggestions(
        path=tp0.pootle_path).count())
Exemple #19
0
def test_log_get_suggestions(member, store0):
    suggestions = Suggestion.objects.all()
    sugg_start, sugg_end = _get_mid_times(suggestions)
    sugg_log = Log()
    sugg_events = sugg_log.get_suggestion_events()
    assert type(sugg_events).__name__ == "generator"
    user_time_suggestions = (
        (sugg_log.filter_users(sugg_log.suggestions, [member], field="user_id")
         & sugg_log.filter_timestamps(
             sugg_log.suggestions, start=sugg_start, end=sugg_end))
        | (sugg_log.filter_users(sugg_log.suggestions, [member],
                                 field="reviewer_id")
           & sugg_log.filter_timestamps(sugg_log.suggestions,
                                        start=sugg_start,
                                        end=sugg_end,
                                        field="review_time")))
    assert user_time_suggestions
    pending = suggestions.filter(creation_time__gte=sugg_start,
                                 creation_time__lt=sugg_end,
                                 state__name="pending").first()
    review.get(Suggestion)([pending], member).accept()
    pending = suggestions.filter(creation_time__gte=sugg_start,
                                 creation_time__lt=sugg_end,
                                 state__name="pending").first()
    review.get(Suggestion)([pending], member).reject()
    pending.review_time = sugg_start
    pending.save()
    expected = {}
    for suggestion in user_time_suggestions.all():
        add_event = ((suggestion.creation_time >= sugg_start)
                     and (suggestion.creation_time < sugg_end)
                     and (suggestion.user == member))
        review_event = ((suggestion.review_time >= sugg_start)
                        and (suggestion.review_time < sugg_end)
                        and (suggestion.reviewer == member))
        expected[suggestion.id] = {}
        if add_event:
            expected[suggestion.id]["suggestion_created"] = (sugg_log.event(
                suggestion.unit, suggestion.user, suggestion.creation_time,
                "suggestion_created", suggestion))
        if review_event:
            event_name = ("suggestion_accepted" if suggestion.state.name
                          == "accepted" else "suggestion_rejected")
            expected[suggestion.id][event_name] = (sugg_log.event(
                suggestion.unit, suggestion.reviewer, suggestion.review_time,
                event_name, suggestion))
    result = sugg_log.get_suggestion_events(start=sugg_start,
                                            end=sugg_end,
                                            users=[member.id])
    for event in result:
        assert isinstance(event, sugg_log.event)
        sugg_review = expected[event.value.pk][event.action]
        assert event.unit == sugg_review.unit
        assert event.action in [
            "suggestion_created", "suggestion_accepted", "suggestion_rejected"
        ]
        assert event.user == (sugg_review.value.user
                              if event.action == "suggestion_created" else
                              sugg_review.value.reviewer)
        assert event.timestamp == (sugg_review.value.creation_time
                                   if event.action == "suggestion_created" else
                                   sugg_review.value.review_time)
        assert event.value == sugg_review.value
Exemple #20
0
def test_log_filtered_created_units(system, tp0, store0):
    created_units = UnitSource.objects.all()
    created_unit_start, created_unit_end = _get_mid_times(
        created_units, field="unit__creation_time")
    created_unit_log = Log()
    # no filtering
    assert (created_unit_log.filtered_created_units(include_meta=True).count()
            == created_unit_log.created_units.count() == created_units.count())
    user_created_units = created_unit_log.filter_users(
        created_unit_log.created_units, [system.id],
        field="created_by_id",
        include_meta=True)
    assert user_created_units.count()
    assert (list(user_created_units) == list(
        created_unit_log.filtered_created_units(users=[system])))
    # using start and end seems to create empty - so only testing start
    time_created_units = created_unit_log.filter_timestamps(
        created_unit_log.created_units,
        start=created_unit_start,
        field="unit__creation_time")
    assert time_created_units.count()
    assert (list(time_created_units) == list(
        created_unit_log.filtered_created_units(start=created_unit_start,
                                                include_meta=True)))
    store_created_units = created_unit_log.filter_store(
        created_unit_log.created_units, store0.pk)
    assert store_created_units.count()
    assert (list(
        created_unit_log.filtered_created_units(
            store=store0.pk, include_meta=True)) == list(store_created_units))
    path_created_units = created_unit_log.filter_path(
        created_unit_log.created_units, tp0.pootle_path)
    assert path_created_units.count()
    assert (created_unit_log.filtered_created_units(
        path=tp0.pootle_path,
        include_meta=True).count() == path_created_units.count())