|
24 | 24 | from .base import StudioTestCase |
25 | 25 | from .helpers import clear_tasks |
26 | 26 | from .testdata import channel |
| 27 | +from .testdata import create_studio_file |
27 | 28 | from .testdata import node as create_node |
28 | 29 | from .testdata import slideshow |
29 | 30 | from contentcuration import models as cc |
|
38 | 39 | pytestmark = pytest.mark.django_db |
39 | 40 |
|
40 | 41 |
|
| 42 | +thumbnail_bytes = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\nIDATx\x9cc\x00\x01\x00\x00\x05\x00\x01\r\n-\xb4\x00\x00\x00\x00IEND\xaeB`\x82' # noqa E501 |
| 43 | + |
| 44 | + |
41 | 45 | def description(): |
42 | 46 | return "".join(random.sample(string.printable, 20)) |
43 | 47 |
|
@@ -116,11 +120,35 @@ def setUp(self): |
116 | 120 | new_exercise.complete = True |
117 | 121 | new_exercise.parent = current_exercise.parent |
118 | 122 | new_exercise.save() |
| 123 | + thumbnail_data = create_studio_file(thumbnail_bytes, preset="exercise_thumbnail", ext="png") |
| 124 | + file_obj = thumbnail_data["db_file"] |
| 125 | + file_obj.contentnode = new_exercise |
| 126 | + file_obj.save() |
119 | 127 | for ai in current_exercise.assessment_items.all(): |
120 | 128 | ai.id = None |
121 | 129 | ai.contentnode = new_exercise |
122 | 130 | ai.save() |
123 | 131 |
|
| 132 | + legacy_extra_fields = { |
| 133 | + 'mastery_model': exercises.M_OF_N, |
| 134 | + 'randomize': True, |
| 135 | + 'm': 1, |
| 136 | + 'n': 2 |
| 137 | + } |
| 138 | + |
| 139 | + legacy_exercise = create_node({'kind_id': 'exercise', 'title': 'Legacy Mastery test', 'extra_fields': legacy_extra_fields}) |
| 140 | + legacy_exercise.complete = True |
| 141 | + legacy_exercise.parent = current_exercise.parent |
| 142 | + legacy_exercise.save() |
| 143 | + thumbnail_data = create_studio_file(thumbnail_bytes, preset="exercise_thumbnail", ext="png") |
| 144 | + file_obj = thumbnail_data["db_file"] |
| 145 | + file_obj.contentnode = legacy_exercise |
| 146 | + file_obj.save() |
| 147 | + for ai in current_exercise.assessment_items.all(): |
| 148 | + ai.id = None |
| 149 | + ai.contentnode = legacy_exercise |
| 150 | + ai.save() |
| 151 | + |
124 | 152 | first_topic = self.content_channel.main_tree.get_descendants().first() |
125 | 153 |
|
126 | 154 | # Add a publishable topic to ensure it does not inherit but that its children do |
@@ -357,6 +385,23 @@ def test_child_no_inherit_learning_activity(self): |
357 | 385 | # Should only be the learning activities we set on the child directly, not any parent ones. |
358 | 386 | self.assertEqual(first_child.learning_activities, learning_activities.LISTEN) |
359 | 387 |
|
| 388 | + def test_publish_no_modify_exercise_extra_fields(self): |
| 389 | + exercise = cc.ContentNode.objects.get(title="Mastery test") |
| 390 | + self.assertEqual(exercise.extra_fields["options"]["completion_criteria"]["threshold"], { |
| 391 | + "m": 1, |
| 392 | + "n": 2, |
| 393 | + "mastery_model": exercises.M_OF_N, |
| 394 | + }) |
| 395 | + |
| 396 | + def test_publish_no_modify_legacy_exercise_extra_fields(self): |
| 397 | + current_exercise = cc.ContentNode.objects.get(title="Legacy Mastery test") |
| 398 | + self.assertEqual(current_exercise.extra_fields, { |
| 399 | + 'mastery_model': exercises.M_OF_N, |
| 400 | + 'randomize': True, |
| 401 | + 'm': 1, |
| 402 | + 'n': 2 |
| 403 | + }) |
| 404 | + |
360 | 405 |
|
361 | 406 | class ChannelExportUtilityFunctionTestCase(StudioTestCase): |
362 | 407 | @classmethod |
|
0 commit comments