-
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: basic get/post endpoint for v2 xblocks. TNL-10873
- Loading branch information
Ken Clary
committed
Jul 20, 2023
1 parent
ebd9605
commit d6f824d
Showing
7 changed files
with
139 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
URL_BLOCK_RENDER_VIEW, | ||
URL_BLOCK_GET_HANDLER_URL, | ||
URL_BLOCK_METADATA_URL, | ||
URL_BLOCK_FIELDS_URL, | ||
) | ||
from openedx.core.djangoapps.content_libraries.tests.user_state_block import UserStateTestBlock | ||
from openedx.core.djangoapps.content_libraries.constants import COMPLEX, ALL_RIGHTS_RESERVED, CC_4_BY | ||
|
@@ -42,6 +43,9 @@ def setUp(self): | |
self.student_a = UserFactory.create(username="Alice", email="[email protected]", password="edx") | ||
self.student_b = UserFactory.create(username="Bob", email="[email protected]", password="edx") | ||
|
||
# staff user | ||
self.staff_user = UserFactory(password="edx", is_staff=True) | ||
|
||
# Create a collection using Blockstore API directly only because there | ||
# is not yet any Studio REST API for doing so: | ||
self.collection = blockstore_api.create_collection("Content Library Test Collection") | ||
|
@@ -182,6 +186,43 @@ def test_xblock_metadata(self): | |
assert metadata_view_result.data['student_view_data'] is None | ||
# Capa doesn't provide student_view_data | ||
|
||
@skip_unless_cms # modifying blocks only works properly in Studio | ||
def test_xblock_fields(self): | ||
""" | ||
Test the XBlock fields API | ||
""" | ||
# act as staff: | ||
client = APIClient() | ||
client.login(username=self.staff_user.username, password='edx') | ||
|
||
# create/save a block using the library APIs first | ||
unit_block_key = library_api.create_library_block(self.library.key, "unit", "fields-u1").usage_key | ||
block_key = library_api.create_library_block_child(unit_block_key, "html", "fields-p1").usage_key | ||
new_olx = """ | ||
<html display_name="New Text Block"> | ||
<p>This is some <strong>HTML</strong>.</p> | ||
</html> | ||
""".strip() | ||
library_api.set_library_block_olx(block_key, new_olx) | ||
library_api.publish_changes(self.library.key) | ||
|
||
# Check the GET API for the block: | ||
fields_get_result = client.get(URL_BLOCK_FIELDS_URL.format(block_key=block_key)) | ||
assert fields_get_result.data['display_name'] == 'New Text Block' | ||
assert fields_get_result.data['data'].strip() == '<p>This is some <strong>HTML</strong>.</p>' | ||
assert fields_get_result.data['metadata']['display_name'] == 'New Text Block' | ||
|
||
# Check the POST API for the block: | ||
fields_post_result = client.post(URL_BLOCK_FIELDS_URL.format(block_key=block_key), data={ | ||
'data': '<p>test</p>', | ||
'metadata': { | ||
'display_name': 'New Display Name', | ||
} | ||
}, format='json') | ||
block_saved = xblock_api.load_block(block_key, self.staff_user) | ||
assert block_saved.data == '\n<p>test</p>\n' | ||
assert xblock_api.get_block_display_name(block_saved) == 'New Display Name' | ||
|
||
|
||
@requires_blockstore | ||
class ContentLibraryRuntimeBServiceTest(ContentLibraryRuntimeTestMixin, TestCase): | ||
|
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 was deleted.
Oops, something went wrong.
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