Skip to content

Commit

Permalink
Pick a value for line_item_url in all contexts
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
marcospri committed Aug 10, 2023
1 parent 7c7635a commit 37c7eff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lms/services/lti_grading/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/lms/services/lti_grading/factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 37c7eff

Please sign in to comment.