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_user( 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( user=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())
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_user( sub_log.submissions, member)) assert user_subs.count() assert ( list(user_subs) == list(sub_log.filtered_submissions(user=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())
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_suggestions() assert type(sugg_events).__name__ == "generator" user_time_suggestions = ( (sugg_log.filter_user( sugg_log.suggestions, member, field="user_id") & sugg_log.filter_timestamps( sugg_log.suggestions, start=sugg_start, end=sugg_end)) | (sugg_log.filter_user( 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_suggestions( start=sugg_start, end=sugg_end, user=member) 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
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_user( sugg_log.suggestions, member, field="user_id") | sugg_log.filter_user( sugg_log.suggestions, member, field="reviewer_id")) assert user_suggestions assert ( list(user_suggestions.order_by("id")) == list(sugg_log.filtered_suggestions( user=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_user( sugg_log.suggestions, member, field="user_id") & sugg_log.filter_timestamps( sugg_log.suggestions, start=sugg_start, end=sugg_end)) | (sugg_log.filter_user( 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, user=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())