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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import ddt
from opaque_keys.edx.keys import UsageKey
from openedx_content.api import signals as content_signals
from openedx_events.content_authoring.signals import (
LIBRARY_BLOCK_DELETED,
XBLOCK_CREATED,
Expand Down Expand Up @@ -405,6 +406,7 @@ class ClipboardPasteFromV2LibraryTestCase(OpenEdxEventsTestMixin, ImmediateOnCom
Test Clipboard Paste functionality with a "new" (as of Sumac) library
"""
ENABLED_OPENEDX_EVENTS = [
content_signals.ENTITIES_DRAFT_CHANGED.event_type, # Required for library events to work
LIBRARY_BLOCK_DELETED.event_type,
XBLOCK_CREATED.event_type,
XBLOCK_DELETED.event_type,
Expand Down Expand Up @@ -491,7 +493,8 @@ def test_paste_from_library_read_only_tags(self):
assert object_tag.is_copied

# If we delete the upstream library block...
library_api.delete_library_block(self.lib_block_key)
with self.captureOnCommitCallbacks(execute=True): # make event handlers fire now, within TestCase transaction
library_api.delete_library_block(self.lib_block_key)

# ...the copied tags remain, but should no longer be marked as "copied"
object_tags = tagging_api.get_object_tags(new_block_key)
Expand Down
4 changes: 0 additions & 4 deletions cms/djangoapps/modulestore_migrator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,13 +895,9 @@ def _migrate_container(
).publishable_entity_version

# Publish the container
# Call post publish events synchronously to avoid
# an error when calling `wait_for_post_publish_events`
# inside a celery task.
libraries_api.publish_container_changes(
container.container_key,
context.created_by,
call_post_publish_events_sync=True,
)
context.used_container_slugs.add(container.container_key.container_id)
return container_publishable_entity_version, None
Expand Down
20 changes: 13 additions & 7 deletions openedx/core/djangoapps/content/search/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,9 @@ def test_delete_collection(self, mock_meilisearch) -> None:
"""
# Add a component to the collection
updated_date = datetime(2023, 6, 7, 8, 9, 10, tzinfo=timezone.utc) # noqa: UP017
with freeze_time(updated_date):
# Note: because TestCase keeps the transaction open, we need self.captureOnCommitCallbacks(execute=True) to
# ensure events get emitted here as if this part were its own transaction as it normally would be.
with freeze_time(updated_date), self.captureOnCommitCallbacks(execute=True):
library_api.update_library_collection_items(
self.library.key,
collection_key=self.collection.collection_code,
Expand Down Expand Up @@ -942,10 +944,11 @@ def test_delete_collection(self, mock_meilisearch) -> None:
mock_meilisearch.return_value.index.reset_mock()

# Soft-delete the collection
content_api.delete_collection(
self.collection.learning_package_id,
self.collection.collection_code,
)
with self.captureOnCommitCallbacks(execute=True):
content_api.delete_collection(
self.collection.learning_package_id,
self.collection.collection_code,
)

doc_problem_without_collection = {
"id": self.doc_problem1["id"],
Expand Down Expand Up @@ -976,7 +979,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:

# Restore the collection
restored_date = datetime(2023, 8, 9, 10, 11, 12, tzinfo=timezone.utc) # noqa: UP017
with freeze_time(restored_date):
with freeze_time(restored_date), self.captureOnCommitCallbacks(execute=True):
content_api.restore_collection(
self.collection.learning_package_id,
self.collection.collection_code,
Expand Down Expand Up @@ -1055,7 +1058,10 @@ def clear_contents(data: dict):
'sections': {'display_name': [], 'key': []},
}]))

library_api.delete_container(container.container_key)
# Note: because TestCase keeps the transaction open, we need self.captureOnCommitCallbacks(execute=True) to
# ensure events get emitted here as if this part were its own transaction as it normally would be.
with self.captureOnCommitCallbacks(execute=True):
library_api.delete_container(container.container_key)

mock_meilisearch.return_value.index.return_value.delete_document.assert_called_once_with(
container_dict["id"],
Expand Down
36 changes: 19 additions & 17 deletions openedx/core/djangoapps/content/search/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from openedx.core.djangolib.testing.utils import skip_unless_cms
from xmodule.modulestore.tests.django_utils import (
TEST_DATA_SPLIT_MODULESTORE,
ImmediateOnCommitMixin,
ModuleStoreTestCase,
)

Expand All @@ -29,7 +28,7 @@
@patch("openedx.core.djangoapps.content.search.api.MeilisearchClient")
@override_settings(MEILISEARCH_ENABLED=True)
@skip_unless_cms
class TestUpdateIndexHandlers(ImmediateOnCommitMixin, ModuleStoreTestCase, LiveServerTestCase):
class TestUpdateIndexHandlers(ModuleStoreTestCase, LiveServerTestCase):
"""
Test that the search index is updated when XBlocks and Library Blocks are modified
"""
Expand Down Expand Up @@ -63,7 +62,9 @@ def test_create_delete_xblock(self, meilisearch_client):

# Create XBlocks
created_date = datetime(2023, 4, 5, 6, 7, 8, tzinfo=timezone.utc) # noqa: UP017
with freeze_time(created_date):
# Note: because TestCase keeps the transaction open, we need self.captureOnCommitCallbacks(execute=True) to
# ensure events get emitted here as if this part were its own transaction as it normally would be.
with freeze_time(created_date), self.captureOnCommitCallbacks(execute=True):
sequential = self.store.create_child(self.user_id, course.location, "sequential", "test_sequential")
doc_sequential = {
"id": "block-v1orgatest_coursetest_runtypesequentialblocktest_sequential-0cdb9395",
Expand All @@ -86,7 +87,7 @@ def test_create_delete_xblock(self, meilisearch_client):

meilisearch_client.return_value.index.return_value.update_documents.assert_called_with([doc_sequential])

with freeze_time(created_date):
with freeze_time(created_date), self.captureOnCommitCallbacks(execute=True):
vertical = self.store.create_child(self.user_id, sequential.location, "vertical", "test_vertical")
doc_vertical = {
"id": "block-v1orgatest_coursetest_runtypeverticalblocktest_vertical-011f143b",
Expand Down Expand Up @@ -117,7 +118,7 @@ def test_create_delete_xblock(self, meilisearch_client):
sequential = self.store.get_item(sequential.location, self.user_id) # Refresh the XBlock
sequential.display_name = "Updated Sequential"
modified_date = datetime(2024, 5, 6, 7, 8, 9, tzinfo=timezone.utc) # noqa: UP017
with freeze_time(modified_date):
with freeze_time(modified_date), self.captureOnCommitCallbacks(execute=True):
self.store.update_item(sequential, self.user_id)

# The display name and the child's breadcrumbs should be updated
Expand All @@ -131,7 +132,8 @@ def test_create_delete_xblock(self, meilisearch_client):
])

# Delete the XBlock
self.store.delete_item(vertical.location, self.user_id)
with self.captureOnCommitCallbacks(execute=True):
self.store.delete_item(vertical.location, self.user_id)

meilisearch_client.return_value.index.return_value.delete_document.assert_called_with(
"block-v1orgatest_coursetest_runtypeverticalblocktest_vertical-011f143b"
Expand Down Expand Up @@ -166,8 +168,12 @@ def test_create_delete_library_block(self, meilisearch_client):

# Populate it with a problem, freezing the date so we can verify created date serializes correctly.
created_date = datetime(2023, 4, 5, 6, 7, 8, tzinfo=timezone.utc) # noqa: UP017
with freeze_time(created_date):

# Note: because TestCase keeps the transaction open, we need self.captureOnCommitCallbacks(execute=True) to
# ensure events get emitted here as if this part were its own transaction as it normally would be.
with freeze_time(created_date), self.captureOnCommitCallbacks(execute=True):
problem = library_api.create_library_block(library.key, "problem", "Problem1")

doc_problem = {
"id": "lborgalib_aproblemproblem1-ca3186e9",
"type": "library_block",
Expand Down Expand Up @@ -197,33 +203,29 @@ def test_create_delete_library_block(self, meilisearch_client):

# Edit the problem block, freezing the date so we can verify modified date serializes correctly
modified_date = datetime(2024, 5, 6, 7, 8, 9, tzinfo=timezone.utc) # noqa: UP017
with freeze_time(modified_date):
with freeze_time(modified_date), self.captureOnCommitCallbacks(execute=True):
library_api.set_library_block_olx(problem.usage_key, "<problem />")
doc_problem["modified"] = modified_date.timestamp()
meilisearch_client.return_value.index.return_value.update_documents.assert_called_with([doc_problem])

# Publish the content library, freezing the date so we can verify last_published date serializes correctly
published_date = datetime(2024, 6, 7, 8, 9, 10, tzinfo=timezone.utc) # noqa: UP017
with freeze_time(published_date):
with freeze_time(published_date), self.captureOnCommitCallbacks(execute=True):
library_api.publish_changes(library.key)
doc_problem["last_published"] = published_date.timestamp()
doc_problem["published"] = {"display_name": "Blank Problem"}
doc_problem["publish_status"] = "published"
meilisearch_client.return_value.index.return_value.update_documents.assert_called_with([doc_problem])

# Delete the Library Block
library_api.delete_library_block(problem.usage_key)
with self.captureOnCommitCallbacks(execute=True):
library_api.delete_library_block(problem.usage_key)

meilisearch_client.return_value.index.return_value.delete_document.assert_called_with(
"lborgalib_aproblemproblem1-ca3186e9"
)

# Restore the Library Block
library_api.restore_library_block(problem.usage_key)
with self.captureOnCommitCallbacks(execute=True):
library_api.restore_library_block(problem.usage_key)
meilisearch_client.return_value.index.return_value.update_documents.assert_any_call([doc_problem])
meilisearch_client.return_value.index.return_value.update_documents.assert_any_call(
[{'id': doc_problem['id'], 'collections': {'display_name': [], 'key': []}}]
)
meilisearch_client.return_value.index.return_value.update_documents.assert_any_call(
[{'id': doc_problem['id'], 'tags': {}}]
)
Loading
Loading