Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test PR | Enable Extracted LTI Block #36020

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
name: ${{ matrix.shard_name }}(py=${{ matrix.python-version }},dj=${{ matrix.django-version }},mongo=${{ matrix.mongo-version }})
runs-on: ${{ matrix.os-version }}
strategy:
fail-fast: false
matrix:
python-version:
- "3.11"
Expand Down
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
2 changes: 1 addition & 1 deletion lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5606,7 +5606,7 @@ def _should_send_learning_badge_events(settings):
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_LTI_BLOCK = False
USE_EXTRACTED_LTI_BLOCK = True

# .. toggle_name: USE_EXTRACTED_HTML_BLOCK
# .. toggle_default: False
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ xblock-utils==4.0.0
# via
# edx-sga
# xblock-poll
xblocks-contrib==0.2.0
git+https://github.com/ttqureshi/xblocks-contrib.git@ttqureshi/lti-xblock
# via -r requirements/edx/bundled.in
xmlsec==1.3.14
# via python3-saml
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2273,7 +2273,7 @@ xblock-utils==4.0.0
# -r requirements/edx/testing.txt
# edx-sga
# xblock-poll
xblocks-contrib==0.2.0
git+https://github.com/ttqureshi/xblocks-contrib.git@ttqureshi/lti-xblock
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ xblock-utils==4.0.0
# -r requirements/edx/base.txt
# edx-sga
# xblock-poll
xblocks-contrib==0.2.0
git+https://github.com/ttqureshi/xblocks-contrib.git@ttqureshi/lti-xblock
# via -r requirements/edx/base.txt
xmlsec==1.3.14
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ xblock-utils==4.0.0
# -r requirements/edx/base.txt
# edx-sga
# xblock-poll
xblocks-contrib==0.2.0
git+https://github.com/ttqureshi/xblocks-contrib.git@ttqureshi/lti-xblock
# via -r requirements/edx/base.txt
xmlsec==1.3.14
# via
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
Loading