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

PR review suggestions #622

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

from common.djangoapps.student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase
from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory

from .... import api
from ....models import ContentObjectTag
from ..objecttag_export_helpers import TaggedContent, build_object_tree_with_objecttags, iterate_with_level


Expand All @@ -23,7 +25,6 @@ def setUp(self):
super().setUp()
# Create user
self.user = UserFactory.create()
self.user_id = self.user.id

self.orgA = Organization.objects.create(name="Organization A", short_name="orgA")
self.taxonomy_1 = api.create_taxonomy(name="Taxonomy 1")
Expand Down Expand Up @@ -54,12 +55,11 @@ def setUp(self):
self.patcher.start()

# Create course
self.course = self.store.create_course(
self.orgA.short_name,
"test_course",
"test_run",
self.user_id,
fields={'display_name': "Test Course"},
self.course = CourseFactory.create(
org=self.orgA.short_name,
number="test_course",
run="test_run",
display_name="Test Course",
)
course_tags = api.tag_content_object(
object_key=self.course.id,
Expand All @@ -68,17 +68,21 @@ def setUp(self):
)

self.expected_tagged_xblock = TaggedContent(
display_name=self.course.display_name_with_default,
block_id=str(self.course.id),
category=self.course.category,
display_name="Test Course",
block_id="course-v1:orgA+test_course+test_run",
category="course",
children=[],
object_tags={
self.taxonomy_1.id: list(course_tags),
},
)

# Create XBlocks
self.sequential = self.store.create_child(self.user_id, self.course.location, "sequential", "test_sequential")
self.sequential = BlockFactory.create(
parent=self.course,
category="sequential",
display_name="test sequential",
)
# Tag blocks
sequential_tags1 = api.tag_content_object(
object_key=self.sequential.location,
Expand All @@ -90,11 +94,10 @@ def setUp(self):
taxonomy=self.taxonomy_2,
tags=['Tag 2.1'],
)
xblock = self.store.get_item(self.sequential.location)
tagged_sequential = TaggedContent(
display_name=xblock.display_name_with_default,
block_id=str(xblock.location),
category=xblock.category,
display_name="test sequential",
block_id="block-v1:orgA+test_course+test_run+type@sequential+block@test_sequential",
category="sequential",
children=[],
object_tags={
self.taxonomy_1.id: list(sequential_tags1),
Expand All @@ -105,17 +108,51 @@ def setUp(self):
assert self.expected_tagged_xblock.children is not None # type guard
self.expected_tagged_xblock.children.append(tagged_sequential)

vertical = self.store.create_child(self.user_id, self.sequential.location, "vertical", "test_vertical1")
# Untagged blocks
sequential2 = BlockFactory.create(
parent=self.course,
category="sequential",
display_name="untagged sequential",
)
untagged_sequential = TaggedContent(
display_name="untagged sequential",
block_id="block-v1:orgA+test_course+test_run+type@sequential+block@untagged_sequential",
category="sequential",
children=[],
object_tags={},
)
assert self.expected_tagged_xblock.children is not None # type guard
self.expected_tagged_xblock.children.append(untagged_sequential)
BlockFactory.create(
parent=sequential2,
category="vertical",
display_name="untagged vertical",
)
untagged_vertical = TaggedContent(
display_name="untagged vertical",
block_id="block-v1:orgA+test_course+test_run+type@vertical+block@untagged_vertical",
category="vertical",
children=[],
object_tags={},
)
assert untagged_sequential.children is not None # type guard
untagged_sequential.children.append(untagged_vertical)
# /Untagged blocks

vertical = BlockFactory.create(
parent=self.sequential,
category="vertical",
display_name="test vertical1",
)
vertical_tags = api.tag_content_object(
object_key=vertical.location,
taxonomy=self.taxonomy_2,
tags=['Tag 2.2'],
)
xblock = self.store.get_item(vertical.location)
tagged_vertical = TaggedContent(
display_name=xblock.display_name_with_default,
block_id=str(xblock.location),
category=xblock.category,
display_name="test vertical1",
block_id="block-v1:orgA+test_course+test_run+type@vertical+block@test_vertical1",
category="vertical",
children=[],
object_tags={
self.taxonomy_2.id: list(vertical_tags),
Expand All @@ -125,29 +162,35 @@ def setUp(self):
assert tagged_sequential.children is not None # type guard
tagged_sequential.children.append(tagged_vertical)

vertical2 = self.store.create_child(self.user_id, self.sequential.location, "vertical", "test_vertical2")
xblock = self.store.get_item(vertical2.location)
vertical2 = BlockFactory.create(
parent=self.sequential,
category="vertical",
display_name="test vertical2",
)
tagged_vertical2 = TaggedContent(
display_name=xblock.display_name_with_default,
block_id=str(xblock.location),
category=xblock.category,
display_name="test vertical2",
block_id="block-v1:orgA+test_course+test_run+type@vertical+block@test_vertical2",
category="vertical",
children=[],
object_tags={},
)
assert tagged_sequential.children is not None # type guard
tagged_sequential.children.append(tagged_vertical2)

html = self.store.create_child(self.user_id, vertical2.location, "html", "test_html")
html = BlockFactory.create(
parent=vertical2,
category="html",
display_name="test html",
)
html_tags = api.tag_content_object(
object_key=html.location,
taxonomy=self.taxonomy_2,
tags=['Tag 2.1'],
)
xblock = self.store.get_item(html.location)
tagged_text = TaggedContent(
display_name=xblock.display_name_with_default,
block_id=str(xblock.location),
category=xblock.category,
display_name="test html",
block_id="block-v1:orgA+test_course+test_run+type@html+block@test_html",
category="html",
children=[],
object_tags={
self.taxonomy_2.id: list(html_tags),
Expand All @@ -157,13 +200,30 @@ def setUp(self):
assert tagged_vertical2.children is not None # type guard
tagged_vertical2.children.append(tagged_text)

# Create "deleted" object tags, which will be omitted from the results.
for object_id in (
self.course.id,
self.sequential.location,
vertical.location,
html.location,
):
ContentObjectTag.objects.create(
object_id=str(object_id),
taxonomy=None,
tag=None,
_value="deleted tag",
_name="deleted taxonomy",
)

self.all_object_tags, _ = api.get_all_object_tags(self.course.id)
self.expected_tagged_content_list = [
(self.expected_tagged_xblock, 0),
(tagged_sequential, 1),
(tagged_vertical, 2),
(tagged_vertical2, 2),
(tagged_text, 3),
(untagged_sequential, 1),
(untagged_vertical, 2),
]


Expand Down
Loading