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

Add test for and support for copying metadata fields. #3569

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions contentcuration/contentcuration/db/models/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ def get_source_attributes(self, source):
"author": source.author,
"provider": source.provider,
"role_visibility": source.role_visibility,
"grade_levels": source.grade_levels,
"resource_types": source.resource_types,
"learning_activities": source.learning_activities,
"accessibility_labels": source.accessibility_labels,
"categories": source.categories,
"learner_needs": source.learner_needs,
}

def _clone_node(
Expand Down
6 changes: 6 additions & 0 deletions contentcuration/contentcuration/tests/test_contentnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ def _check_node_copy(source, copy, original_channel_id=None, channel=None):
assert child_copy.aggregator == child_source.aggregator
assert child_copy.provider == child_source.provider
assert child_copy.role_visibility == child_source.role_visibility
assert child_copy.grade_levels == child_source.grade_levels
assert child_copy.resource_types == child_source.resource_types
assert child_copy.learning_activities == child_source.learning_activities
assert child_copy.accessibility_labels == child_source.accessibility_labels
assert child_copy.categories == child_source.categories
assert child_copy.learner_needs == child_source.learner_needs
assert child_copy.changed
assert not child_copy.published
assert child_copy.complete == child_source.complete
Expand Down
18 changes: 18 additions & 0 deletions contentcuration/contentcuration/utils/db_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
from le_utils.constants import file_formats
from le_utils.constants import format_presets
from le_utils.constants import licenses
from le_utils.constants.labels.accessibility_categories import (
ACCESSIBILITYCATEGORIESLIST,
)
from le_utils.constants.labels.learning_activities import LEARNINGACTIVITIESLIST
from le_utils.constants.labels.levels import LEVELSLIST
from le_utils.constants.labels.needs import NEEDSLIST
from le_utils.constants.labels.resource_type import RESOURCETYPELIST
from le_utils.constants.labels.subjects import SUBJECTSLIST

from contentcuration.api import write_file_to_storage
from contentcuration.models import AssessmentItem
Expand Down Expand Up @@ -266,6 +274,10 @@ def uuid4_hex():
return uuid.uuid4().hex


def choices(sequence, k):
return [random.choice(sequence) for _ in range(0, k)]


class TreeBuilder(object):
"""
This class is purely to generate all the relevant data for a single
Expand Down Expand Up @@ -510,4 +522,10 @@ def contentnode_data(self, parent_id=None, kind=None, extra_fields=None, complet
"parent_id": parent_id,
"kind_id": kind,
"complete": complete,
"resource_types": {c: True for c in choices(RESOURCETYPELIST, k=random.randint(1, 2))},
"learning_activities": {c: True for c in choices(LEARNINGACTIVITIESLIST, k=random.randint(1, 3))},
"accessibility_labels": {c: True for c in choices(ACCESSIBILITYCATEGORIESLIST, k=random.randint(1, 3))},
"grade_levels": {c: True for c in choices(LEVELSLIST, k=random.randint(1, 2))},
"categories": {c: True for c in choices(SUBJECTSLIST, k=random.randint(1, 10))},
"learner_needs": {c: True for c in choices(NEEDSLIST, k=random.randint(1, 5))},
}