Skip to content

Commit

Permalink
test: api to restore soft-deleted components
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Dec 9, 2024
1 parent b189f61 commit f1186af
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions openedx/core/djangoapps/content/search/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,7 @@ def test_create_delete_library_block(self, meilisearch_client):
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)
meilisearch_client.return_value.index.return_value.update_documents.assert_called_with([doc_problem])
29 changes: 29 additions & 0 deletions openedx/core/djangoapps/content_libraries/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,35 @@ def test_delete_library_block(self):
event_receiver.call_args_list[0].kwargs,
)

def test_restore_library_block(self):
api.update_library_collection_components(
self.lib1.library_key,
self.col1.key,
usage_keys=[
UsageKey.from_string(self.lib1_problem_block["id"]),
UsageKey.from_string(self.lib1_html_block["id"]),
],
)

event_receiver = mock.Mock()
LIBRARY_COLLECTION_UPDATED.connect(event_receiver)

api.restore_library_block(UsageKey.from_string(self.lib1_problem_block["id"]))

assert event_receiver.call_count == 1
self.assertDictContainsSubset(
{
"signal": LIBRARY_COLLECTION_UPDATED,
"sender": None,
"library_collection": LibraryCollectionData(
self.lib1.library_key,
collection_key=self.col1.key,
background=True,
),
},
event_receiver.call_args_list[0].kwargs,
)

def test_add_component_and_revert(self):
# Add component and publish
api.update_library_collection_components(
Expand Down
20 changes: 18 additions & 2 deletions openedx/core/djangoapps/content_tagging/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
from common.djangoapps.student.tests.factories import UserFactory
from openedx.core.djangolib.testing.utils import skip_unless_cms
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, ModuleStoreTestCase
from openedx.core.djangoapps.content_libraries.api import create_library, create_library_block, delete_library_block
from openedx.core.djangoapps.content_libraries.api import (
create_library, create_library_block, delete_library_block, restore_library_block
)

from .. import api
from ..models.base import TaxonomyOrg
Expand Down Expand Up @@ -267,7 +269,7 @@ def test_waffle_disabled_create_delete_xblock(self):
# Still no tags
assert self._check_tag(usage_key_str, LANGUAGE_TAXONOMY_ID, None)

def test_create_delete_library_block(self):
def test_create_delete_restore_library_block(self):
# Create library
library = create_library(
org=self.orgA,
Expand All @@ -293,6 +295,13 @@ def test_create_delete_library_block(self):
# Check if the tags are deleted
assert self._check_tag(usage_key_str, LANGUAGE_TAXONOMY_ID, None)

# Restore the XBlock
with patch('crum.get_current_request', return_value=fake_request):
restore_library_block(library_block.usage_key)

# Check if the tags are restored in the Library Block with the user's preferred language
assert self._check_tag(usage_key_str, LANGUAGE_TAXONOMY_ID, 'Português (Brasil)')

@override_waffle_flag(CONTENT_TAGGING_AUTO, active=False)
def test_waffle_disabled_create_delete_library_block(self):
# Create library
Expand All @@ -319,3 +328,10 @@ def test_waffle_disabled_create_delete_library_block(self):

# Still no tags
assert self._check_tag(usage_key_str, LANGUAGE_TAXONOMY_ID, None)

# Restore the XBlock
with patch('crum.get_current_request', return_value=fake_request):
restore_library_block(library_block.usage_key)

# Still no tags
assert self._check_tag(usage_key_str, LANGUAGE_TAXONOMY_ID, None)

0 comments on commit f1186af

Please sign in to comment.