From 37c7eff0836cd89ec39c041a5b796c8ad2c1fb8f Mon Sep 17 00:00:00 2001 From: Marcos Prieto Date: Wed, 9 Aug 2023 10:14:50 +0200 Subject: [PATCH] Pick a value for line_item_url in all contexts The grading service might operate in two different contexts: - While on a launch Here take the value directly from LTIParams - On an API call from the front end Here we will forward the value to the frontend which will send it back in `parsed_params` --- lms/services/lti_grading/factory.py | 5 ++++- .../lms/services/lti_grading/factory_test.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lms/services/lti_grading/factory.py b/lms/services/lti_grading/factory.py index a1f329699f..6600c99469 100644 --- a/lms/services/lti_grading/factory.py +++ b/lms/services/lti_grading/factory.py @@ -8,7 +8,10 @@ def service_factory(_context, request): if application_instance.lti_version == "1.3.0": return LTI13GradingService( - line_item_url=request.parsed_params.get("lis_outcome_service_url"), + # Pick the value from the right dictionary depending on the context we are running + # either an API call from the frontend (parsed_params) or inside an LTI launch (lti_params). + line_item_url=request.parsed_params.get("lis_outcome_service_url") + or request.lti_params.get("lis_outcome_service_url"), line_item_container_url=request.lti_params.get("lineitems"), ltia_service=request.find_service(LTIAHTTPService), ) diff --git a/tests/unit/lms/services/lti_grading/factory_test.py b/tests/unit/lms/services/lti_grading/factory_test.py index 8e99e783bc..45e0de0a99 100644 --- a/tests/unit/lms/services/lti_grading/factory_test.py +++ b/tests/unit/lms/services/lti_grading/factory_test.py @@ -28,12 +28,28 @@ def test_v13(self, pyramid_request, LTI13GradingService, ltia_http_service): ) assert svc == LTI13GradingService.return_value + def test_v13_line_item_url_from_lti_params( + self, pyramid_request, LTI13GradingService, ltia_http_service + ): + del pyramid_request.parsed_params["lis_outcome_service_url"] + pyramid_request.lti_user.application_instance = Mock(lti_version="1.3.0") + + svc = service_factory(sentinel.context, pyramid_request) + + LTI13GradingService.assert_called_once_with( + sentinel.grading_url, sentinel.lineitems, ltia_http_service + ) + assert svc == LTI13GradingService.return_value + @pytest.fixture def pyramid_request(self, pyramid_request): pyramid_request.parsed_params = { "lis_outcome_service_url": sentinel.grading_url } - pyramid_request.lti_params = {"lineitems": sentinel.lineitems} + pyramid_request.lti_params = { + "lineitems": sentinel.lineitems, + "lis_outcome_service_url": sentinel.grading_url, + } return pyramid_request