Skip to content

Commit

Permalink
Overwrite mastery_model for quiz modality.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed Nov 16, 2021
1 parent 4a2c610 commit 4c12298
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kolibri/core/content/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
25 changes: 25 additions & 0 deletions kolibri/core/content/test/test_content_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4c12298

Please sign in to comment.