Skip to content

Commit

Permalink
fix: fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ttqureshi committed Nov 8, 2024
1 parent f6237b1 commit 8ea48d4
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 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 All @@ -16,6 +17,7 @@
from lxml import etree
from openassessment.workflow.errors import AssessmentWorkflowError
from openassessment.xblock import openassessmentblock
from openassessment.xblock.openassessmentblock import load
from openassessment.xblock.utils import defaults
from openassessment.xblock.utils.resolve_dates import DateValidationError, DISTANT_FUTURE, DISTANT_PAST
from openassessment.xblock.openassesment_template_mixin import UI_MODELS
Expand Down Expand Up @@ -130,14 +132,6 @@ def test_load_author_view(self, xblock):
self.assertIn("OpenAssessmentBlock", xblock_fragment.body_html())
self.assertIn("IS_STUDIO", xblock_fragment.body_html())

# Test that calling update_workflow_status doesn't throw an error.
try:
xblock.update_workflow_status()
except AssessmentWorkflowError:
self.fail(
"update_workflow_status raised AssessmentWorkflowError unexpectedly!"
)

def _staff_assessment_view_helper(self, xblock):
"""
Helper for "staff_assessment_view" tests
Expand Down Expand Up @@ -1447,3 +1441,23 @@ 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 TestLoadFunction(unittest.TestCase):
"""Test case for the load function in openassessmentblock.py."""

@patch("openassessment.xblock.openassessmentblock.resource_loader.load_unicode")
def test_load_function(self, mock_load_unicode):
"""
Test that load calls resource_loader.load_unicode with the correct path.
"""
mock_load_unicode.return_value = "Sample content"
test_path = "sample/path/to/resource.html"

result = load(test_path)

# Check that resource_loader.load_unicode was called with the correct path
mock_load_unicode.assert_called_once_with(test_path)

# Verify that load() returns the expected value
self.assertEqual(result, "Sample content")

0 comments on commit 8ea48d4

Please sign in to comment.