Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds regression test for and fixes metadata label syncing. #3712

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions contentcuration/contentcuration/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
from le_utils.constants import content_kinds
from le_utils.constants import file_formats
from le_utils.constants import format_presets
from le_utils.constants.labels import accessibility_categories
from le_utils.constants.labels import learning_activities
from le_utils.constants.labels import levels
from le_utils.constants.labels import needs
from le_utils.constants.labels import resource_type
from le_utils.constants.labels import subjects

from .base import StudioTestCase
from .testdata import create_temp_file
Expand Down Expand Up @@ -270,6 +276,55 @@ def test_sync_tags_add_multiple_tags(self):

self.assertTrue(self.derivative_channel.has_changes())

def test_sync_channel_metadata_labels(self):
"""
Test that calling sync channel will also bring in metadata label updates.
"""

self.assertFalse(self.channel.has_changes())
self.assertFalse(self.derivative_channel.has_changes())

labels = {
"categories": subjects.MATHEMATICS,
"learner_needs": needs.PRIOR_KNOWLEDGE,
"accessibility_labels": accessibility_categories.CAPTIONS_SUBTITLES,
"grade_levels": levels.LOWER_SECONDARY,
"resource_types": resource_type.LESSON_PLAN,
"learning_activities": learning_activities.LISTEN,
}

contentnode = (
self.channel.main_tree.get_descendants()
.exclude(kind_id=content_kinds.TOPIC)
.first()
)

target_child = self.derivative_channel.main_tree.get_descendants().get(
source_node_id=contentnode.node_id
)

self.assertIsNotNone(target_child)

for key, value in labels.items():
setattr(contentnode, key, {value: True})
contentnode.save()

sync_channel(
self.derivative_channel,
sync_attributes=True,
sync_tags=False,
sync_files=False,
sync_assessment_items=False,
)

self.assertTrue(self.channel.has_changes())
self.assertTrue(self.derivative_channel.has_changes())

target_child.refresh_from_db()

for key, value in labels.items():
self.assertEqual(getattr(target_child, key), {value: True})


class ContentIDTestCase(SyncTestMixin, StudioAPITestCase):
def setUp(self):
Expand Down
24 changes: 18 additions & 6 deletions contentcuration/contentcuration/utils/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,25 @@ def sync_node(
return node


synced_fields = [
"title",
"description",
"license_id",
"copyright_holder",
"author",
"extra_fields",
"categories",
"learner_needs",
"accessibility_labels",
"grade_levels",
"resource_types",
"learning_activities",
]


def sync_node_data(node, original):
node.title = original.title
node.description = original.description
node.license_id = original.license_id
node.copyright_holder = original.copyright_holder
node.author = original.author
node.extra_fields = original.extra_fields
for field in synced_fields:
setattr(node, field, getattr(original, field))
# Set changed if anything has changed
node.on_update()

Expand Down