diff --git a/evap/results/tests/test_views.py b/evap/results/tests/test_views.py index fe2ab06ab9d76dfe84a7ab665b3802f916266770..d36dba806673f60f64e2d545b69753bdebdf64b1 100644 --- a/evap/results/tests/test_views.py +++ b/evap/results/tests/test_views.py @@ -20,6 +20,7 @@ from evap.evaluation.models import ( Evaluation, Question, Questionnaire, + RatingAnswerCounter, Semester, UserProfile, ) @@ -31,7 +32,7 @@ from evap.evaluation.tests.tools import ( ) from evap.results.exporters import TextAnswerExporter from evap.results.tools import cache_results -from evap.results.views import get_evaluations_with_prefetched_data +from evap.results.views import get_evaluations_with_prefetched_data, warm_up_template_cache from evap.staff.tests.utils import WebTestStaffMode, helper_exit_staff_mode, run_in_staff_mode @@ -264,6 +265,32 @@ class TestResultsView(WebTest): caches["sessions"].clear() caches["results"].clear() + def test_evaluation_weight_sums(self): + """Regression test for #1691""" + student = baker.make(UserProfile, email="student@institution.example.com") + course = baker.make(Course) + + published = baker.make( + Evaluation, + course=course, + name_en=iter(["ev1", "ev2", "ev3"]), + name_de=iter(["ev1", "ev2", "ev3"]), + state=iter([Evaluation.State.NEW, Evaluation.State.PUBLISHED, Evaluation.State.PUBLISHED]), + weight=iter([8, 3, 4]), + is_single_result=True, + _quantity=3, + )[1:] + + contributions = [e.general_contribution for e in published] + baker.make(RatingAnswerCounter, contribution=iter(contributions), answer=2, count=2, _quantity=len(published)) + warm_up_template_cache(published) + + page = self.app.get(self.url, user=student) + decoded = page.body.decode() + + self.assertTrue(decoded.index("ev2") < decoded.index(" 20% ") < decoded.index("ev3") < decoded.index(" 26% ")) + self.assertNotContains(page, " 53% ") + class TestGetEvaluationsWithPrefetchedData(TestCase): def test_returns_correct_participant_count(self): diff --git a/evap/results/tools.py b/evap/results/tools.py index 4cd3633defe89cf7a9244dabb881935da9529930..4482565fb766a69c0194a3c7516a12d3f30e7487 100644 --- a/evap/results/tools.py +++ b/evap/results/tools.py @@ -298,8 +298,8 @@ def get_evaluations_with_course_result_attributes(evaluations): ) course_id_evaluation_weight_sum_pairs = ( - Course.objects.filter(evaluations__in=evaluations) - .annotate(Sum("evaluations__weight")) + Course.objects.annotate(Sum("evaluations__weight")) + .filter(pk__in=Course.objects.filter(evaluations__in=evaluations)) # is needed, see #1691 .values_list("id", "evaluations__weight__sum") )