def test_valid_launch(self, render): """ Verifies that the view returns OK if called with the correct context """ request = build_run_request() views.lti_run(request) render.assert_called_with(request, ALL_PARAMS['usage_key'])
def test_lti_consumer_record_supplemented_with_guid(self, _render): request = build_run_request() request.session[views.LTI_SESSION_KEY]["tool_consumer_instance_guid"] = "instance_guid" with self.assertNumQueries(4): views.lti_run(request) consumer = models.LtiConsumer.objects.get(consumer_key=LTI_DEFAULT_PARAMS["oauth_consumer_key"]) self.assertEqual(consumer.instance_guid, "instance_guid")
def test_valid_launch(self, render): """ Verifies that the view returns OK if called with the correct context """ request = build_run_request() views.lti_run(request) render.assert_called_with(request, ALL_PARAMS["usage_key"])
def test_session_cleared_in_view(self, _render): """ Verifies that the LTI parameters are cleaned out of the session after launching the view to prevent a launch being replayed. """ request = build_run_request() views.lti_run(request) self.assertNotIn(views.LTI_SESSION_KEY, request.session)
def test_lti_consumer_record_supplemented_with_guid(self, _render): request = build_run_request() request.session[views.LTI_SESSION_KEY][ 'tool_consumer_instance_guid'] = 'instance_guid' with self.assertNumQueries(4): views.lti_run(request) consumer = models.LtiConsumer.objects.get( consumer_key=LTI_DEFAULT_PARAMS['oauth_consumer_key']) self.assertEqual(consumer.instance_guid, 'instance_guid')
def test_valid_launch(self): """ Verifies that the view returns OK if called with the correct context """ request = self.build_request() response = views.lti_run(request) self.assertEqual(response.status_code, 200)
def test_forbidden_if_session_key_missing(self): """ Verifies that the lti_run view returns a Forbidden status if the session doesn't have an entry for the LTI parameters. """ request = build_run_request() del request.session[views.LTI_SESSION_KEY] response = views.lti_run(request) self.assertEqual(response.status_code, 403)
def test_forbidden_if_session_incomplete(self): """ Verifies that the lti_run view returns a Forbidden status if the session is missing any of the required LTI parameters or course information. """ extra_keys = ["course_key", "usage_key"] for key in views.REQUIRED_PARAMETERS + extra_keys: request = build_run_request() del request.session[views.LTI_SESSION_KEY][key] response = views.lti_run(request) self.assertEqual(response.status_code, 403, "Expected Forbidden response when session is missing " + key)
def test_forbidden_if_session_incomplete(self): """ Verifies that the lti_run view returns a Forbidden status if the session is missing any of the required LTI parameters or course information. """ extra_keys = ['course_key', 'usage_key'] for key in views.REQUIRED_PARAMETERS + extra_keys: request = build_run_request() del request.session[views.LTI_SESSION_KEY][key] response = views.lti_run(request) self.assertEqual( response.status_code, 403, 'Expected Forbidden response when session is missing ' + key)