def get_launch_message(self): """ Return the LTI 1.3 launch message object for the current request. """ launch_message = DjangoMessageLaunch( self.request, self.lti_tool_config, launch_data_storage=self.lti_tool_storage) # This will force the LTI launch validation steps. launch_message.get_launch_data() return launch_message
def test_send_scores(self): from pylti1p3.contrib.django import DjangoMessageLaunch tool_conf = get_test_tool_conf() with patch.object(DjangoMessageLaunch, "_get_jwt_body", autospec=True) as get_jwt_body: message_launch = DjangoMessageLaunch(DjangoFakeRequest(), tool_conf) get_jwt_body.side_effect = lambda x: self._get_jwt_body() with patch('socket.gethostbyname', return_value="127.0.0.1"): with requests_mock.Mocker() as m: m.post(self._get_auth_token_url(), text=json.dumps(self._get_auth_token_response())) m.get( 'http://canvas.docker/api/lti/courses/1/line_items', text=json.dumps([{ 'scoreMaximum': 100.0, 'tag': 'score', 'id': 'http://canvas.docker/api/lti/courses/1/line_items/1', 'label': 'Score' }])) expected_result = { 'resultUrl': 'http://canvas.docker/api/lti/courses/1/line_items/1/results/4' } m.post( 'http://canvas.docker/api/lti/courses/1/line_items/1/scores', text=json.dumps(expected_result)) ags = message_launch.validate_registration().get_ags() sub = message_launch.get_launch_data().get('sub') timestamp = datetime.datetime.utcnow().strftime( '%Y-%m-%dT%H:%M:%S+0000') sc = Grade() sc.set_score_given(5) \ .set_score_maximum(100) \ .set_timestamp(timestamp) \ .set_activity_progress('Completed') \ .set_grading_progress('FullyGraded') \ .set_user_id(sub) sc_line_item = LineItem() sc_line_item.set_tag('score') \ .set_score_maximum(100) \ .set_label('Score') resp = ags.put_grade(sc, sc_line_item) self.assertEqual(expected_result, resp['body'])
def _launch(self, request, tool_conf, key_set_url_response=None, force_validation=False): from pylti1p3.contrib.django import DjangoMessageLaunch obj = DjangoMessageLaunch(request, tool_conf) obj.set_jwt_verify_options({ 'verify_aud': False, 'verify_exp': False }) with patch('socket.gethostbyname', return_value="127.0.0.1"): with requests_mock.Mocker() as m: key_set_url_text = key_set_url_response if key_set_url_response else json.dumps(self.jwt_canvas_keys) m.get(TOOL_CONFIG[self.iss]['key_set_url'], text=key_set_url_text) if force_validation: return obj.validate() else: return obj.get_launch_data()