Skip to content
Open
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
5 changes: 5 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v0/serializers/xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ class XblockSerializer(StrictSerializer):
target_index = serializers.IntegerField(required=False, allow_null=True)
boilerplate = serializers.JSONField(required=False, allow_null=True)
staged_content = serializers.CharField(required=False, allow_null=True)
# Present when a course block is created by importing a component from a v2
# library. Consumed by the create handler (``create_xblock_response`` reads
# ``library_content_key`` to set the block's upstream reference). Declared
# here so the strict serializer does not 400 the real Studio create payload.
library_content_key = serializers.CharField(required=False, allow_null=True)
hide_from_toc = serializers.BooleanField(required=False, allow_null=True)
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ def test_post_calls_create_xblock_response(self, mock_fn):
mock_fn.assert_called_once()
assert mock_fn.call_args[0][0].method == "POST"

@patch(f"{_VIEW_MODULE}.create_xblock_response", return_value=_MOCK_RESPONSE)
def test_create_accepts_library_content_key(self, mock_fn):
"""
Creating a course block by importing a component from a v2 library sends
``library_content_key`` on the create body (consumed by
``create_xblock_response`` to set the upstream reference). The strict
XblockSerializer must accept it so the request reaches the handler rather
than returning a 400.
"""
data = {
"parent_locator": PARENT_LOCATOR,
"category": "library_content",
"library_content_key": "lct:edX:testlib:unit:u1",
}
response = self.client.post(_list_url(), data=data, format="json")
assert response.status_code == status.HTTP_200_OK
mock_fn.assert_called_once()

@patch(f"{_VIEW_MODULE}.retrieve_xblock_response", return_value=_MOCK_RESPONSE)
def test_get_calls_retrieve_xblock_response(self, mock_fn):
response = self.client.get(_detail_url())
Expand Down
Loading