From 0f7a34db6a2dc0250247139ed0bab5d5ad2b5372 Mon Sep 17 00:00:00 2001 From: Muhammad Tayayb Tahir Qureshi Date: Fri, 1 Nov 2024 12:37:18 +0500 Subject: [PATCH] test: Add test case to ResourceLoader import in openassessmentblock --- .../xblock/test/test_openassessment.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/openassessment/xblock/test/test_openassessment.py b/openassessment/xblock/test/test_openassessment.py index aacf70d0c2..58968a0ac5 100644 --- a/openassessment/xblock/test/test_openassessment.py +++ b/openassessment/xblock/test/test_openassessment.py @@ -5,6 +5,7 @@ import datetime as dt from io import StringIO import json +import unittest from unittest import mock from unittest.mock import MagicMock, Mock, PropertyMock, patch from django.test.utils import override_settings @@ -1422,3 +1423,21 @@ def test_ora_indexibility_with_multiple_html_prompt(self, xblock): self.assertEqual(content["display_name"], "Open Response Assessment") self.assertEqual(content["prompt_0"], "What is computer? It is a machine") self.assertEqual(content["prompt_1"], "Is it a calculator? Or is it a microwave") + + + +class TestResourceLoaderImport(unittest.TestCase): + @patch('xblock.utils.resources') + def test_import_falls_back(self, mock_resources): + # Simulate a ModuleNotFoundError for the first import + mock_resources.ResourceLoader.side_effect = ModuleNotFoundError + + # Now try to import and check if the fallback works + try: + from openassessmentblock import ResourceLoader + except ImportError: + self.fail("Import should not raise ImportError") + + # Check if ResourceLoader is the one from xblockutils.resources + from xblockutils.resources import ResourceLoader as FallbackLoader + self.assertIs(ResourceLoader, FallbackLoader)