Skip to content

Commit

Permalink
test: Testing index for published blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Oct 19, 2024
1 parent f6a25fa commit 87be898
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 2 deletions.
7 changes: 5 additions & 2 deletions openedx/core/djangoapps/content/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class implementation returns only:
Fields.org: str(block.usage_key.context_key.org),
Fields.access_id: _meili_access_id_from_context_key(block.usage_key.context_key),
Fields.breadcrumbs: [],
Fields.description: None,
}
# Get the breadcrumbs (course, section, subsection, etc.):
if block.usage_key.context_key.is_course: # Getting parent is not yet implemented in Learning Core (for libraries).
Expand Down Expand Up @@ -347,10 +346,14 @@ def _published_data_from_block(block_published) -> dict:

try:
content_data = _get_content_from_block(block_published)
result[Fields.published][Fields.published_description] = _get_description_from_block_content(

description = _get_description_from_block_content(
block_published.scope_ids.block_type,
content_data,
)

if description:
result[Fields.published][Fields.published_description] = description
except Exception as err: # pylint: disable=broad-except
log.exception(f"Failed to process index_dictionary for {block_published.usage_key}: {err}")

Expand Down
125 changes: 125 additions & 0 deletions openedx/core/djangoapps/content/search/tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def test_problem_block(self):
"org": "edX",
"access_id": self.toy_course_access_id,
"display_name": "Test Problem",
"description": "What is a test?",
"breadcrumbs": [
{
'display_name': 'Toy Course',
Expand Down Expand Up @@ -202,6 +203,8 @@ def test_html_block(self):
"org": "edX",
"access_id": self.toy_course_access_id,
"display_name": "Text",
"description": "This is a link to another page and some Chinese 四節比分和七年前 Some "
"more Chinese 四節比分和七年前 ",
"breadcrumbs": [
{
'display_name': 'Toy Course',
Expand Down Expand Up @@ -297,6 +300,128 @@ def test_html_library_block(self):
},
}

def test_html_published_library_block(self):
library_api.publish_changes(self.library.key)

doc = searchable_doc_for_library_block(self.library_block)
doc.update(searchable_doc_tags(self.library_block.usage_key))
doc.update(searchable_doc_collections(self.library_block.usage_key))

assert doc == {
"id": "lbedx2012_fallhtmltext2-4bb47d67",
"type": "library_block",
"block_type": "html",
"usage_key": "lb:edX:2012_Fall:html:text2",
"block_id": "text2",
"context_key": "lib:edX:2012_Fall",
"org": "edX",
"access_id": self.library_access_id,
"display_name": "Text",
"breadcrumbs": [
{
"display_name": "some content_library",
},
],
"last_published": None,
"created": 1680674828.0,
"modified": 1680674828.0,
"content": {
"html_content": "",
},
"collections": {
"key": ["TOY_COLLECTION"],
"display_name": ["Toy Collection"],
},
"tags": {
"taxonomy": ["Difficulty"],
"level0": ["Difficulty > Normal"],
},
'published': {'display_name': 'Text'},
}

# Update library block to create a draft
olx_str = '<html display_name="Text 2"><![CDATA[<p>This is a Test</p>]]></html>'
library_api.set_library_block_olx(self.library_block.usage_key, olx_str)

doc = searchable_doc_for_library_block(self.library_block)
doc.update(searchable_doc_tags(self.library_block.usage_key))
doc.update(searchable_doc_collections(self.library_block.usage_key))

assert doc == {
"id": "lbedx2012_fallhtmltext2-4bb47d67",
"type": "library_block",
"block_type": "html",
"usage_key": "lb:edX:2012_Fall:html:text2",
"block_id": "text2",
"context_key": "lib:edX:2012_Fall",
"org": "edX",
"access_id": self.library_access_id,
"display_name": "Text 2",
"description": "This is a Test",
"breadcrumbs": [
{
"display_name": "some content_library",
},
],
"last_published": None,
"created": 1680674828.0,
"modified": 1680674828.0,
"content": {
"html_content": "This is a Test",
},
"collections": {
"key": ["TOY_COLLECTION"],
"display_name": ["Toy Collection"],
},
"tags": {
"taxonomy": ["Difficulty"],
"level0": ["Difficulty > Normal"],
},
"published": {"display_name": "Text"},
}

# Publish new changes
library_api.publish_changes(self.library.key)
doc = searchable_doc_for_library_block(self.library_block)
doc.update(searchable_doc_tags(self.library_block.usage_key))
doc.update(searchable_doc_collections(self.library_block.usage_key))

assert doc == {
"id": "lbedx2012_fallhtmltext2-4bb47d67",
"type": "library_block",
"block_type": "html",
"usage_key": "lb:edX:2012_Fall:html:text2",
"block_id": "text2",
"context_key": "lib:edX:2012_Fall",
"org": "edX",
"access_id": self.library_access_id,
"display_name": "Text 2",
"description": "This is a Test",
"breadcrumbs": [
{
"display_name": "some content_library",
},
],
"last_published": None,
"created": 1680674828.0,
"modified": 1680674828.0,
"content": {
"html_content": "This is a Test",
},
"collections": {
"key": ["TOY_COLLECTION"],
"display_name": ["Toy Collection"],
},
"tags": {
"taxonomy": ["Difficulty"],
"level0": ["Difficulty > Normal"],
},
"published": {
"display_name": "Text 2",
"description": "This is a Test",
},
}

def test_collection_with_library(self):
doc = searchable_doc_for_collection(self.library.key, self.collection.key)
doc.update(searchable_doc_tags_for_collection(self.library.key, self.collection.key))
Expand Down

0 comments on commit 87be898

Please sign in to comment.