Skip to content

Commit

Permalink
test: Add test case to ResourceLoader import in openassessmentblock
Browse files Browse the repository at this point in the history
  • Loading branch information
ttqureshi committed Nov 1, 2024
1 parent 1fc4c48 commit 0f7a34d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions openassessment/xblock/test/test_openassessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 0f7a34d

Please sign in to comment.