Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ttqureshi committed Feb 21, 2025
1 parent 12b2ef4 commit 8a886fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
22 changes: 18 additions & 4 deletions lms/djangoapps/courseware/tests/test_lti_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import OrderedDict

from unittest import mock
from unittest.mock import patch
import urllib
import oauthlib
from django.conf import settings
Expand All @@ -16,6 +17,7 @@
from openedx.core.lib.url_utils import quote_slashes
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.tests.helpers import mock_render_template


class TestLTI(BaseTestXmodule):
Expand Down Expand Up @@ -115,14 +117,26 @@ def mocked_sign(self, *args, **kwargs):
patcher.start()
self.addCleanup(patcher.stop)

def test_lti_constructor(self):
@patch('xblock.utils.resources.ResourceLoader.render_django_template', side_effect=mock_render_template)
def test_lti_constructor(self, mock_render_django_template):
generated_content = self.block.student_view(None).content
expected_content = self.runtime.render_template('lti.html', self.expected_context)

if settings.USE_EXTRACTED_LTI_BLOCK:
expected_content = self.runtime.render_template('templates/lti.html', self.expected_context)
mock_render_django_template.assert_called_once()
else:
expected_content = self.runtime.render_template('lti.html', self.expected_context)
assert generated_content == expected_content

def test_lti_preview_handler(self):
@patch('xblock.utils.resources.ResourceLoader.render_django_template', side_effect=mock_render_template)
def test_lti_preview_handler(self, mock_render_django_template):
generated_content = self.block.preview_handler(None, None).body
expected_content = self.runtime.render_template('lti_form.html', self.expected_context)

if settings.USE_EXTRACTED_LTI_BLOCK:
expected_content = self.runtime.render_template('templates/lti_form.html', self.expected_context)
mock_render_django_template.assert_called_once()
else:
expected_content = self.runtime.render_template('lti_form.html', self.expected_context)
assert generated_content.decode('utf-8') == expected_content


Expand Down
7 changes: 6 additions & 1 deletion xmodule/tests/test_lti20_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
import datetime
import textwrap
import unittest
from django.conf import settings
from unittest.mock import Mock

from pytz import UTC
from xblock.field_data import DictFieldData

from xmodule.lti_2_util import LTIError
from xmodule.lti_block import LTIBlock
from xmodule.tests.helpers import StubUserService

from . import get_test_system

if settings.USE_EXTRACTED_LTI_BLOCK:
from xblocks_contrib.lti.lti_2_util import LTIError
else:
from xmodule.lti_2_util import LTIError


class LTI20RESTResultServiceTest(unittest.TestCase):
"""Logic tests for LTI block. LTI2.0 REST ResultService"""
Expand Down
6 changes: 5 additions & 1 deletion xmodule/tests/test_lti_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@

from common.djangoapps.xblock_django.constants import ATTR_KEY_ANONYMOUS_USER_ID
from xmodule.fields import Timedelta
from xmodule.lti_2_util import LTIError
from xmodule.lti_block import LTIBlock
from xmodule.tests.helpers import StubUserService

from . import get_test_system

if settings.USE_EXTRACTED_LTI_BLOCK:
from xblocks_contrib.lti.lti_2_util import LTIError
else:
from xmodule.lti_2_util import LTIError


@override_settings(LMS_BASE="edx.org")
class LTIBlockTest(TestCase):
Expand Down

0 comments on commit 8a886fd

Please sign in to comment.