-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: XBlock Mixin and Service for UpstreamSync + link_to_upstream
- Loading branch information
1 parent
cdc402f
commit cfab256
Showing
8 changed files
with
433 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
""" | ||
Test CMS's upstream->downstream syncing system | ||
""" | ||
from organizations.api import ensure_organization | ||
from organizations.models import Organization | ||
|
||
from cms.lib.xblock.upstream_sync import UpstreamSyncService | ||
from openedx.core.djangoapps.content_libraries import api as libs | ||
from openedx.core.djangoapps.xblock import api as xblock | ||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase | ||
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory | ||
|
||
|
||
class UpstreamSyncTestCase(ModuleStoreTestCase): | ||
""" | ||
Tests the UpstreamSyncMixin | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
Create a simple course with a video component. | ||
""" | ||
super().setUp() | ||
course = CourseFactory.create() | ||
chapter = BlockFactory.create( | ||
category='chapter', | ||
parent=course, | ||
display_name='Test Chapter' | ||
) | ||
sequential = BlockFactory.create( | ||
category='sequential', | ||
parent=chapter, | ||
display_name='Test Sequential' | ||
) | ||
vertical = BlockFactory.create( | ||
category='vertical', | ||
parent=sequential, | ||
display_name='Test Vertical' | ||
) | ||
ensure_organization("TestX") | ||
self.upstream_key = libs.create_library_block( | ||
libs.create_library( | ||
org=Organization.objects.get(short_name="TestX"), | ||
slug="TestLib", | ||
title="Test Upstream Library", | ||
).key, | ||
"html", | ||
"test-upstream", | ||
).usage_key | ||
upstream = xblock.load_block(self.upstream_key, self.user) | ||
upstream.display_name = "original upstream title" | ||
upstream.data = "<p>original upstream content</p>" | ||
upstream.save() | ||
downstream = BlockFactory.create(category='html', parent=vertical, upstream=str(self.upstream_key)) | ||
self.sync_service = UpstreamSyncService(self.user) | ||
self.sync_service.sync_from_upstream(downstream, apply_updates=True) | ||
downstream.save() | ||
self.store.update_item(downstream, self.user.id) | ||
self.downstream_key = downstream.usage_key | ||
|
||
def test_sync_to_unmodified_content(self): | ||
""" | ||
Can we sync updates from a content library block to a linked out-of-date course block? | ||
""" | ||
downstream = self.store.get_item(self.downstream_key) | ||
assert downstream.upstream_display_name == "original upstream title" | ||
assert downstream.downstream_customized == set() | ||
assert downstream.display_name == "original upstream title" | ||
assert downstream.data == "\n<p>original upstream content</p>\n" # @@TODO newlines?? | ||
|
||
upstream = xblock.load_block(self.upstream_key, self.user) | ||
upstream.display_name = "NEW upstream title" | ||
upstream.data = "<p>NEW upstream content</p>" | ||
upstream.save() | ||
|
||
self.sync_service.sync_from_upstream(downstream, apply_updates=True) | ||
assert downstream.upstream_display_name == "NEW upstream title" | ||
assert downstream.downstream_customized == set() | ||
assert downstream.display_name == "NEW upstream title" | ||
assert downstream.data == "\n<p>NEW upstream content</p>\n" # @@TODO newlines?? | ||
|
||
def test_sync_to_modified_contenet(self): | ||
""" | ||
If we sync to modified content, will it preserve customizable fields, but overwrite the rest? | ||
""" | ||
downstream = self.store.get_item(self.downstream_key) | ||
downstream.display_name = "downstream OVERRIDE of the title" | ||
downstream.data = "<p>downstream OVERRIDE of the content</p>" | ||
downstream.save() | ||
|
||
upstream = xblock.load_block(self.upstream_key, self.user) | ||
upstream.display_name = "NEW upstream title" | ||
upstream.data = "<p>NEW upstream content</p>" | ||
upstream.save() | ||
|
||
self.sync_service.sync_from_upstream(downstream, apply_updates=True) | ||
assert downstream.upstream_display_name == "NEW upstream title" | ||
assert downstream.downstream_customized == {"display_name"} | ||
assert downstream.display_name == "downstream OVERRIDE of the title" | ||
assert downstream.data == "\n<p>NEW upstream content</p>\n" # @@TODO newlines?? |
Oops, something went wrong.