From 4c12298a86a793c82a99a1e92ab61ed67746d356 Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Mon, 15 Nov 2021 16:31:18 -0800 Subject: [PATCH] Overwrite mastery_model for quiz modality. --- kolibri/core/content/api.py | 10 ++++++++ kolibri/core/content/test/test_content_app.py | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/kolibri/core/content/api.py b/kolibri/core/content/api.py index 2189b2129c5..62aad410617 100644 --- a/kolibri/core/content/api.py +++ b/kolibri/core/content/api.py @@ -27,7 +27,9 @@ from django_filters.rest_framework import NumberFilter from django_filters.rest_framework import UUIDFilter from le_utils.constants import content_kinds +from le_utils.constants import exercises from le_utils.constants import languages +from le_utils.constants import modalities from rest_framework import mixins from rest_framework import status from rest_framework import viewsets @@ -440,6 +442,14 @@ def consolidate(self, items, queryset): ) = self.get_related_data_maps(items, queryset) for item in items: item["assessmentmetadata"] = assessmentmetadata.get(item["id"]) + if ( + item["assessmentmetadata"] + and item["options"] + and item["options"].get("modality") == modalities.QUIZ + ): + item["assessmentmetadata"]["mastery_model"] = { + "type": exercises.QUIZ + } item["tags"] = tags.get(item["id"], []) item["files"] = files_map.get(item["id"], []) lang_id = item.pop("lang_id") diff --git a/kolibri/core/content/test/test_content_app.py b/kolibri/core/content/test/test_content_app.py index bb52f725647..271a86bf396 100644 --- a/kolibri/core/content/test/test_content_app.py +++ b/kolibri/core/content/test/test_content_app.py @@ -13,6 +13,8 @@ from django.test import TestCase from django.utils import timezone from le_utils.constants import content_kinds +from le_utils.constants import exercises +from le_utils.constants import modalities from rest_framework import status from rest_framework.test import APITestCase @@ -791,6 +793,29 @@ def test_contentnode_retrieve(self): ) self.assertEqual(response.data["id"], c1_id.__str__()) + def test_contentnode_retrieve_quiz_modality(self): + node = content.ContentNode.objects.create( + channel_id=uuid.uuid4().hex, + content_id=uuid.uuid4().hex, + id=uuid.uuid4().hex, + options={"modality": modalities.QUIZ}, + available=True, + ) + mastery_model = {"type": exercises.M_OF_N, "m": 8, "n": 10} + content.AssessmentMetaData.objects.create( + mastery_model=mastery_model, + contentnode=node, + id=uuid.uuid4().hex, + number_of_assessments=20, + ) + response = self.client.get( + reverse("kolibri:core:contentnode-detail", kwargs={"pk": node.id}) + ) + self.assertEqual( + response.data["assessmentmetadata"]["mastery_model"], + {"type": exercises.QUIZ}, + ) + def test_contentnode_descendants_assessments_exercise_node(self): c1 = content.ContentNode.objects.filter(kind=content_kinds.EXERCISE).first() c1_id = c1.id