Skip to content
Snippets Groups Projects
Unverified Commit cf9cfff7 authored by Kakadus's avatar Kakadus Committed by GitHub
Browse files

Fix #1691: Make evaluation weight add up to 100% (#1695)

parent 482aa81d
Branches
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ from evap.evaluation.models import ( ...@@ -20,6 +20,7 @@ from evap.evaluation.models import (
Evaluation, Evaluation,
Question, Question,
Questionnaire, Questionnaire,
RatingAnswerCounter,
Semester, Semester,
UserProfile, UserProfile,
) )
...@@ -31,7 +32,7 @@ from evap.evaluation.tests.tools import ( ...@@ -31,7 +32,7 @@ from evap.evaluation.tests.tools import (
) )
from evap.results.exporters import TextAnswerExporter from evap.results.exporters import TextAnswerExporter
from evap.results.tools import cache_results 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 from evap.staff.tests.utils import WebTestStaffMode, helper_exit_staff_mode, run_in_staff_mode
...@@ -264,6 +265,32 @@ class TestResultsView(WebTest): ...@@ -264,6 +265,32 @@ class TestResultsView(WebTest):
caches["sessions"].clear() caches["sessions"].clear()
caches["results"].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): class TestGetEvaluationsWithPrefetchedData(TestCase):
def test_returns_correct_participant_count(self): def test_returns_correct_participant_count(self):
......
...@@ -298,8 +298,8 @@ def get_evaluations_with_course_result_attributes(evaluations): ...@@ -298,8 +298,8 @@ def get_evaluations_with_course_result_attributes(evaluations):
) )
course_id_evaluation_weight_sum_pairs = ( course_id_evaluation_weight_sum_pairs = (
Course.objects.filter(evaluations__in=evaluations) Course.objects.annotate(Sum("evaluations__weight"))
.annotate(Sum("evaluations__weight")) .filter(pk__in=Course.objects.filter(evaluations__in=evaluations)) # is needed, see #1691
.values_list("id", "evaluations__weight__sum") .values_list("id", "evaluations__weight__sum")
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment