Exemple #1
0
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
Exemple #2
0
def _calculate_timeline(request, unit):
    groups = []
    log = UnitTimelineLog(unit)
    grouped_events_class = grouped_events.get(log.__class__)
    target_event = None
    for _key, group in grouped_events_class(log).grouped_events():
        event_group = EventGroup(group, target_event)
        if event_group.target_event:
            target_event = event_group.target_event
        if event_group.events:
            groups.append(event_group.context)

    context = dict(event_groups=groups)
    context.setdefault(
        'language', ProxyTimelineLanguage(
            unit.store.translation_project.language.code))
    t = loader.get_template('editor/units/xhr_timeline.html')
    return t.render(context=context, request=request)
Exemple #3
0
def _calculate_timeline(request, unit):
    groups = []
    log = UnitTimelineLog(unit)
    grouped_events_class = grouped_events.get(log.__class__)
    target_event = None
    for _key, group in grouped_events_class(log).grouped_events():
        event_group = EventGroup(group, target_event)
        if event_group.target_event:
            target_event = event_group.target_event
        if event_group.events:
            groups.append(event_group.context)

    context = dict(event_groups=groups)
    context.setdefault(
        'language',
        ProxyTimelineLanguage(unit.store.translation_project.language.code))
    t = loader.get_template('editor/units/xhr_timeline.html')
    return t.render(context=context, request=request)
Exemple #4
0
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
Exemple #5
0
def test_timeline_groups(store0, admin, member, member2, system):
    expected = []

    # 8 - unit_created
    unit = store0.addunit(store0.UnitClass(source="Foo"), user=system)
    unit.refresh_from_db()
    current_time = unit.creation_time.replace(microsecond=0)
    no_microseconds = (unit.creation_time == current_time)
    if no_microseconds:
        Unit.objects.filter(id=unit.id).update(
            creation_time=current_time)
    unit.refresh_from_db()
    expected[:0] = [(set(['unit_created']),
                     _format_dt(unit.creation_time, no_microseconds),
                     system)]

    # 7 - suggestion_created
    suggestion_0, __ = review.get(Suggestion)().add(
        unit,
        "Suggestion for Foo",
        user=member)
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Suggestion.objects.filter(id=suggestion_0.id).update(
            creation_time=current_time)
        suggestion_0.refresh_from_db()
    expected[:0] = [(set(['suggestion_created']),
                     _format_dt(suggestion_0.creation_time, no_microseconds),
                     member)]

    # 6 - suggestion_created
    suggestion_1, __ = review.get(Suggestion)().add(
        unit,
        "Another suggestion for Foo",
        user=member2)
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Suggestion.objects.filter(id=suggestion_1.id).update(
            creation_time=current_time)
        suggestion_1.refresh_from_db()
    expected[:0] = [(set(['suggestion_created']),
                     _format_dt(suggestion_1.creation_time, no_microseconds),
                     member2)]

    # 5 - comment_updated
    unit.translator_comment = "This is a comment!"
    unit.save(user=member)
    submission = _latest_submission(unit, 1)[0]
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Submission.objects.filter(id=submission.id).update(
            creation_time=current_time)
        submission.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['comment_updated']),
                     _format_dt(submission.creation_time, no_microseconds),
                     member)]

    # 4 - suggestion_accepted, target_updated, state_changed
    review.get(Suggestion)([suggestion_0], admin).accept()
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Suggestion.objects.filter(id=suggestion_0.id).update(
            review_time=current_time)
        Submission.objects.filter(suggestion_id=suggestion_0.id).update(
            creation_time=current_time)
        suggestion_0.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['suggestion_accepted', 'target_updated',
                          'state_changed']),
                     _format_dt(suggestion_0.review_time, no_microseconds),
                     admin)]

    # 3 - target_updated
    unit.target = "Overwritten translation for Foo"
    unit.save(user=member2)
    submission = _latest_submission(unit, 1)[0]
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Submission.objects.filter(id=submission.id).update(
            creation_time=current_time)
        submission.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['target_updated']),
                     _format_dt(submission.creation_time, no_microseconds),
                     member2)]

    # 2 - target_updated, state_changed
    unit.target = ""
    unit.save(user=admin)
    submissions = _latest_submission(unit, 2)
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Submission.objects.filter(id__in=[x.id for x in submissions]).update(
            creation_time=current_time)
        for sub in submissions:
            sub.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['target_updated', 'state_changed']),
                     _format_dt(submissions[0].creation_time, no_microseconds),
                     admin)]

    # 1 - suggestion_rejected
    review.get(Suggestion)([suggestion_1], admin).reject()
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Suggestion.objects.filter(id=suggestion_1.id).update(
            review_time=current_time)
        suggestion_1.refresh_from_db()
    expected[:0] = [(set(['suggestion_rejected']),
                     _format_dt(suggestion_1.review_time, no_microseconds),
                     admin)]

    # 0 - comment_updated
    unit.translator_comment = ""
    unit.save(user=admin)
    submission = _latest_submission(unit, 1)[0]
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Submission.objects.filter(id=submission.id).update(
            creation_time=current_time)
        submission.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['comment_updated']),
                     _format_dt(submission.creation_time, no_microseconds),
                     admin)]

    log = UnitTimelineLog(unit)
    grouped_events_class = grouped_events.get(log.__class__)
    assert grouped_events_class == GroupedEvents
    groups = [list(x) for _j, x in grouped_events_class(log).grouped_events()]
    result = [(set([y.action for y in x]),
               _format_dt(x[0].timestamp, no_microseconds),
               _get_group_user(x)) for x in groups]
    assert expected == result
Exemple #6
0
 def __init__(self, obj):
     self.object = obj
     self.log = UnitTimelineLog(self.object)
     self.events_adapter = grouped_events.get(self.log.__class__)(self.log)
Exemple #7
0
 def __init__(self, obj):
     self.object = obj
     self.log = UnitTimelineLog(self.object)
     self.events_adapter = grouped_events.get(self.log.__class__)(self.log)
Exemple #8
0
def test_timeline_groups(store0, admin, member, member2, system):
    expected = []

    # 8 - unit_created
    unit = store0.addunit(store0.UnitClass(source="Foo"), user=system)
    unit.refresh_from_db()
    current_time = unit.creation_time.replace(microsecond=0)
    no_microseconds = (unit.creation_time == current_time)
    if no_microseconds:
        Unit.objects.filter(id=unit.id).update(
            creation_time=current_time)
    unit.refresh_from_db()
    expected[:0] = [(set(['unit_created']),
                     _format_dt(unit.creation_time, no_microseconds),
                     system)]

    # 7 - suggestion_created
    suggestion_0, __ = review.get(Suggestion)().add(
        unit,
        "Suggestion for Foo",
        user=member)
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Suggestion.objects.filter(id=suggestion_0.id).update(
            creation_time=current_time)
        suggestion_0.refresh_from_db()
    expected[:0] = [(set(['suggestion_created']),
                     _format_dt(suggestion_0.creation_time, no_microseconds),
                     member)]

    # 6 - suggestion_created
    suggestion_1, __ = review.get(Suggestion)().add(
        unit,
        "Another suggestion for Foo",
        user=member2)
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Suggestion.objects.filter(id=suggestion_1.id).update(
            creation_time=current_time)
        suggestion_1.refresh_from_db()
    expected[:0] = [(set(['suggestion_created']),
                     _format_dt(suggestion_1.creation_time, no_microseconds),
                     member2)]

    # 5 - comment_updated
    unit.translator_comment = "This is a comment!"
    unit.save(user=member)
    submission = _latest_submission(unit, 1)[0]
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Submission.objects.filter(id=submission.id).update(
            creation_time=current_time)
        submission.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['comment_updated']),
                     _format_dt(submission.creation_time, no_microseconds),
                     member)]

    # 4 - suggestion_accepted, target_updated, state_changed
    review.get(Suggestion)([suggestion_0], admin).accept()
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Suggestion.objects.filter(id=suggestion_0.id).update(
            review_time=current_time)
        Submission.objects.filter(suggestion_id=suggestion_0.id).update(
            creation_time=current_time)
        suggestion_0.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['suggestion_accepted', 'target_updated',
                          'state_changed']),
                     _format_dt(suggestion_0.review_time, no_microseconds),
                     admin)]

    # 3 - target_updated
    unit.target = "Overwritten translation for Foo"
    unit.save(user=member2)
    submission = _latest_submission(unit, 1)[0]
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Submission.objects.filter(id=submission.id).update(
            creation_time=current_time)
        submission.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['target_updated']),
                     _format_dt(submission.creation_time, no_microseconds),
                     member2)]

    # 2 - target_updated, state_changed
    unit.target = ""
    unit.save(user=admin)
    submissions = _latest_submission(unit, 2)
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Submission.objects.filter(id__in=[x.id for x in submissions]).update(
            creation_time=current_time)
        for sub in submissions:
            sub.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['target_updated', 'state_changed']),
                     _format_dt(submissions[0].creation_time, no_microseconds),
                     admin)]

    # 1 - suggestion_rejected
    review.get(Suggestion)([suggestion_1], admin).reject()
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Suggestion.objects.filter(id=suggestion_1.id).update(
            review_time=current_time)
        suggestion_1.refresh_from_db()
    expected[:0] = [(set(['suggestion_rejected']),
                     _format_dt(suggestion_1.review_time, no_microseconds),
                     admin)]

    # 0 - comment_updated
    unit.translator_comment = ""
    unit.save(user=admin)
    submission = _latest_submission(unit, 1)[0]
    if no_microseconds:
        current_time += timedelta(seconds=1)
        Submission.objects.filter(id=submission.id).update(
            creation_time=current_time)
        submission.refresh_from_db()
    unit.refresh_from_db()
    expected[:0] = [(set(['comment_updated']),
                     _format_dt(submission.creation_time, no_microseconds),
                     admin)]

    log = UnitTimelineLog(unit)
    grouped_events_class = grouped_events.get(log.__class__)
    assert grouped_events_class == GroupedEvents
    groups = [list(x) for _j, x in grouped_events_class(log).grouped_events()]
    result = [(set([y.action for y in x]),
               _format_dt(x[0].timestamp, no_microseconds),
               _get_group_user(x)) for x in groups]
    assert expected == result