Skip to content

Commit

Permalink
Merge pull request #4158 from rtibbles/more_no_string_json
Browse files Browse the repository at this point in the history
Fix publish regression and prevent superfluous data export
  • Loading branch information
bjester authored Jun 20, 2023
2 parents b995463 + a04539e commit bcabc71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 8 additions & 3 deletions contentcuration/contentcuration/tests/test_exportchannel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import absolute_import

import json
import os
import random
import string
Expand Down Expand Up @@ -302,8 +301,8 @@ def test_channel_icon_encoding(self):
def test_assessment_metadata(self):
for i, exercise in enumerate(kolibri_models.ContentNode.objects.filter(kind="exercise")):
asm = exercise.assessmentmetadata.first()
self.assertTrue(isinstance(json.loads(asm.assessment_item_ids), list))
mastery = json.loads(asm.mastery_model)
self.assertTrue(isinstance(asm.assessment_item_ids, list))
mastery = asm.mastery_model
self.assertTrue(isinstance(mastery, dict))
self.assertEqual(mastery["type"], exercises.DO_ALL if i == 0 else exercises.M_OF_N)
self.assertEqual(mastery["m"], 3 if i == 0 else 1)
Expand Down Expand Up @@ -398,6 +397,12 @@ def test_publish_no_modify_exercise_extra_fields(self):
"n": 2,
"mastery_model": exercises.M_OF_N,
})
published_exercise = kolibri_models.ContentNode.objects.get(title="Mastery test")
self.assertEqual(published_exercise.options["completion_criteria"]["threshold"], {
"m": 1,
"n": 2,
"mastery_model": exercises.M_OF_N,
})

def test_publish_no_modify_legacy_exercise_extra_fields(self):
current_exercise = cc.ContentNode.objects.get(title="Legacy Mastery test")
Expand Down
7 changes: 4 additions & 3 deletions contentcuration/contentcuration/utils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import uuid
import zipfile
from builtins import str
from copy import deepcopy
from itertools import chain

from django.conf import settings
Expand Down Expand Up @@ -495,7 +496,7 @@ def process_assessment_metadata(ccnode, kolibrinode):
randomize = extra_fields.get('randomize') if extra_fields.get('randomize') is not None else True
assessment_item_ids = [a.assessment_id for a in assessment_items]

exercise_data = extra_fields.get('options').get('completion_criteria').get('threshold')
exercise_data = deepcopy(extra_fields.get('options').get('completion_criteria').get('threshold'))

exercise_data_type = exercise_data.get('mastery_model', "")

Expand Down Expand Up @@ -527,9 +528,9 @@ def process_assessment_metadata(ccnode, kolibrinode):
kolibrimodels.AssessmentMetaData.objects.create(
id=uuid.uuid4(),
contentnode=kolibrinode,
assessment_item_ids=json.dumps(assessment_item_ids),
assessment_item_ids=assessment_item_ids,
number_of_assessments=assessment_items.count(),
mastery_model=json.dumps(mastery_model),
mastery_model=mastery_model,
randomize=randomize,
is_manipulable=ccnode.kind_id == content_kinds.EXERCISE,
)
Expand Down

0 comments on commit bcabc71

Please sign in to comment.