|
1 | 1 | from __future__ import absolute_import |
2 | 2 |
|
3 | 3 | 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 |
4 | 10 |
|
5 | 11 | from .base import StudioTestCase |
6 | 12 | from .testdata import create_temp_file |
@@ -256,3 +262,52 @@ def test_sync_tags_add_multiple_tags(self): |
256 | 262 | ) |
257 | 263 |
|
258 | 264 | 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}) |
0 commit comments