From c428b969048cfa8eb2c5100138dd70d3540e576a Mon Sep 17 00:00:00 2001 From: Muhammad Tayayb Tahir Qureshi Date: Thu, 12 Dec 2024 13:19:23 +0500 Subject: [PATCH 1/6] chore: enable extracted LTI block --- lms/envs/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/envs/common.py b/lms/envs/common.py index 166966db45b..9f965c76d02 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -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 From 1a5e2262df4c311b582651d84506ece22a4913b4 Mon Sep 17 00:00:00 2001 From: Muhammad Tayayb Tahir Qureshi Date: Thu, 12 Dec 2024 13:26:47 +0500 Subject: [PATCH 2/6] chore: change pip installation to git branch installation --- requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- requirements/edx/doc.txt | 2 +- requirements/edx/testing.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 8b5b24ac9fc..c2e3f30d593 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -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 diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index c912344e06a..491faf61d9a 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -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 diff --git a/requirements/edx/doc.txt b/requirements/edx/doc.txt index 215460d3c3b..e4a84d03fa6 100644 --- a/requirements/edx/doc.txt +++ b/requirements/edx/doc.txt @@ -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 diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 9849c87ed86..af666ff116a 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -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 From 2060533befe9dca7a5de2742fb47bdbde8737a00 Mon Sep 17 00:00:00 2001 From: Muhammad Tayayb Tahir Qureshi Date: Thu, 12 Dec 2024 13:28:48 +0500 Subject: [PATCH 3/6] chore: keep fail-fast false --- .github/workflows/unit-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 9867ac72f27..26cb4038097 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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" From db73396b3ec42cf3ba5e1fad8a6619b27c0e4b4a Mon Sep 17 00:00:00 2001 From: Muhammad Tayyab Tahir Qureshi Date: Thu, 23 Jan 2025 12:39:09 +0500 Subject: [PATCH 4/6] fix: fix tests --- .../courseware/tests/test_lti_integration.py | 22 +++++++++++++++---- xmodule/tests/test_lti20_unit.py | 7 +++++- xmodule/tests/test_lti_unit.py | 6 ++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_lti_integration.py b/lms/djangoapps/courseware/tests/test_lti_integration.py index c9a8a545071..dce20320204 100644 --- a/lms/djangoapps/courseware/tests/test_lti_integration.py +++ b/lms/djangoapps/courseware/tests/test_lti_integration.py @@ -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 @@ -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): @@ -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 diff --git a/xmodule/tests/test_lti20_unit.py b/xmodule/tests/test_lti20_unit.py index 3243c834f36..de3156fdae4 100644 --- a/xmodule/tests/test_lti20_unit.py +++ b/xmodule/tests/test_lti20_unit.py @@ -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""" diff --git a/xmodule/tests/test_lti_unit.py b/xmodule/tests/test_lti_unit.py index 99eb0a28345..0d4d595750b 100644 --- a/xmodule/tests/test_lti_unit.py +++ b/xmodule/tests/test_lti_unit.py @@ -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): From 48be2e418870fcc740f1d084dbd8487064583e8d Mon Sep 17 00:00:00 2001 From: Muhammad Tayyab Tahir Qureshi Date: Thu, 20 Feb 2025 17:17:38 +0500 Subject: [PATCH 5/6] chore: chore From f91f48cfdeb790d4b7ed9d2ecb2dc75c995fdf9b Mon Sep 17 00:00:00 2001 From: Muhammad Tayyab Tahir Qureshi Date: Fri, 21 Feb 2025 10:58:05 +0500 Subject: [PATCH 6/6] chore: chore