From db587bdbe0ea5a47d3b49508906acf608e0b912b Mon Sep 17 00:00:00 2001 From: Jillian Date: Fri, 8 Nov 2024 00:24:26 +1030 Subject: [PATCH] test: re-enable content libraries runtime tests [FC-0062] (#35783) * test: run content_libraries runtime tests * test: fix broken tests * test: fix lms tests Co-authored-by: Kyle D. McCormick --- .../content_libraries/tests/test_runtime.py | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py index 3b505d311162..5fe5bb4eb1fc 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py @@ -2,12 +2,12 @@ Test the Learning-Core-based XBlock runtime and content libraries together. """ import json -from gettext import GNUTranslations -from django.test import TestCase from completion.test_utils import CompletionWaffleTestMixin from django.db import connections, transaction +from django.test import TestCase, override_settings from django.utils.text import slugify +import django.utils.translation from organizations.models import Organization from rest_framework.test import APIClient from xblock.core import XBlock @@ -140,18 +140,17 @@ def test_html_round_trip(self): assert olx_3 == olx_2 == canonical_olx -class ContentLibraryRuntimeTests(ContentLibraryContentTestMixin): +class ContentLibraryRuntimeTests(ContentLibraryContentTestMixin, TestCase): """ Basic tests of the Learning-Core-based XBlock runtime using XBlocks in a content library. """ - def test_dndv2_sets_translator(self): dnd_block_key = library_api.create_library_block(self.library.key, "drag-and-drop-v2", "dnd1").usage_key library_api.publish_changes(self.library.key) dnd_block = xblock_api.load_block(dnd_block_key, self.student_a) i18n_service = dnd_block.runtime.service(dnd_block, 'i18n') - assert isinstance(i18n_service.translator, GNUTranslations) + assert i18n_service.translator is django.utils.translation def test_has_score(self): """ @@ -169,8 +168,7 @@ def test_xblock_metadata(self): """ Test the XBlock metadata API """ - unit_block_key = library_api.create_library_block(self.library.key, "unit", "metadata-u1").usage_key - problem_key = library_api.create_library_block_child(unit_block_key, "problem", "metadata-p1").usage_key + problem_key = library_api.create_library_block(self.library.key, "problem", "metadata-p1").usage_key new_olx = """ @@ -192,14 +190,6 @@ def test_xblock_metadata(self): client = APIClient() client.login(username=self.student_a.username, password='edx') - # Check the metadata API for the unit: - metadata_view_result = client.get( - URL_BLOCK_METADATA_URL.format(block_key=unit_block_key), - {"include": "children,editable_children"}, - ) - assert metadata_view_result.data['children'] == [str(problem_key)] - assert metadata_view_result.data['editable_children'] == [str(problem_key)] - # Check the metadata API for the problem: metadata_view_result = client.get( URL_BLOCK_METADATA_URL.format(block_key=problem_key), @@ -226,8 +216,7 @@ def test_xblock_fields(self): 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 + block_key = library_api.create_library_block(self.library.key, "html", "fields-p1").usage_key new_olx = """

This is some HTML.

@@ -250,14 +239,24 @@ def test_xblock_fields(self): } }, format='json') block_saved = xblock_api.load_block(block_key, self.staff_user) - assert block_saved.data == '\n

test

\n' + assert block_saved.data == '

test

' assert block_saved.display_name == 'New Display Name' +# EphemeralKeyValueStore requires a working cache, and the default test cache is a dummy cache. +@override_settings( + XBLOCK_RUNTIME_V2_EPHEMERAL_DATA_CACHE='default', + CACHES={ + 'default': { + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', + 'LOCATION': 'edx_loc_mem_cache', + }, + }, +) # We can remove the line below to enable this in Studio once we implement a session-backed # field data store which we can use for both studio users and anonymous users @skip_unless_lms -class ContentLibraryXBlockUserStateTest(ContentLibraryContentTestMixin): +class ContentLibraryXBlockUserStateTest(ContentLibraryContentTestMixin, TestCase): """ Test that the Blockstore-based XBlock runtime can store and retrieve student state for XBlocks when learners access blocks directly in a library context, @@ -560,7 +559,7 @@ def test_i18n(self): @skip_unless_lms # No completion tracking in Studio -class ContentLibraryXBlockCompletionTest(ContentLibraryContentTestMixin, CompletionWaffleTestMixin): +class ContentLibraryXBlockCompletionTest(ContentLibraryContentTestMixin, CompletionWaffleTestMixin, TestCase): """ Test that the Blockstore-based XBlocks can track their completion status using the completion library.