Skip to content

Commit 837b692

Browse files
committed
Adds regression test for and fixes metadata label syncing.
1 parent 98f38d8 commit 837b692

2 files changed

Lines changed: 73 additions & 6 deletions

File tree

contentcuration/contentcuration/tests/test_sync.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from __future__ import absolute_import
22

33
from le_utils.constants import content_kinds
4+
from le_utils.constants.labels import accessibility_categories
5+
from le_utils.constants.labels import learning_activities
6+
from le_utils.constants.labels import levels
7+
from le_utils.constants.labels import needs
8+
from le_utils.constants.labels import resource_type
9+
from le_utils.constants.labels import subjects
410

511
from .base import StudioTestCase
612
from .testdata import create_temp_file
@@ -256,3 +262,52 @@ def test_sync_tags_add_multiple_tags(self):
256262
)
257263

258264
self.assertTrue(self.derivative_channel.has_changes())
265+
266+
def test_sync_channel_metadata_labels(self):
267+
"""
268+
Test that calling sync channel will also bring in metadata label updates.
269+
"""
270+
271+
self.assertFalse(self.channel.has_changes())
272+
self.assertFalse(self.derivative_channel.has_changes())
273+
274+
labels = {
275+
"categories": subjects.MATHEMATICS,
276+
"learner_needs": needs.PRIOR_KNOWLEDGE,
277+
"accessibility_labels": accessibility_categories.CAPTIONS_SUBTITLES,
278+
"grade_levels": levels.LOWER_SECONDARY,
279+
"resource_types": resource_type.LESSON_PLAN,
280+
"learning_activities": learning_activities.LISTEN,
281+
}
282+
283+
contentnode = (
284+
self.channel.main_tree.get_descendants()
285+
.exclude(kind_id=content_kinds.TOPIC)
286+
.first()
287+
)
288+
289+
target_child = self.derivative_channel.main_tree.get_descendants().get(
290+
source_node_id=contentnode.node_id
291+
)
292+
293+
self.assertIsNotNone(target_child)
294+
295+
for key, value in labels.items():
296+
setattr(contentnode, key, {value: True})
297+
contentnode.save()
298+
299+
sync_channel(
300+
self.derivative_channel,
301+
sync_attributes=True,
302+
sync_tags=False,
303+
sync_files=False,
304+
sync_assessment_items=False,
305+
)
306+
307+
self.assertTrue(self.channel.has_changes())
308+
self.assertTrue(self.derivative_channel.has_changes())
309+
310+
target_child.refresh_from_db()
311+
312+
for key, value in labels.items():
313+
self.assertEqual(getattr(target_child, key), {value: True})

contentcuration/contentcuration/utils/sync.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,25 @@ def sync_node(
7575
return node
7676

7777

78+
synced_fields = [
79+
"title",
80+
"description",
81+
"license_id",
82+
"copyright_holder",
83+
"author",
84+
"extra_fields",
85+
"categories",
86+
"learner_needs",
87+
"accessibility_labels",
88+
"grade_levels",
89+
"resource_types",
90+
"learning_activities",
91+
]
92+
93+
7894
def sync_node_data(node, original):
79-
node.title = original.title
80-
node.description = original.description
81-
node.license_id = original.license_id
82-
node.copyright_holder = original.copyright_holder
83-
node.author = original.author
84-
node.extra_fields = original.extra_fields
95+
for field in synced_fields:
96+
setattr(node, field, getattr(original, field))
8597
# Set changed if anything has changed
8698
node.on_update()
8799

0 commit comments

Comments
 (0)