From 71ee9d3bb83340c09b6266bd3e5cdfe2434f2fe0 Mon Sep 17 00:00:00 2001 From: Phil McGachey Date: Wed, 3 Jun 2015 12:58:19 -0400 Subject: [PATCH] [LTI Provider] Bugfix in LtiConsumer handling code The line below was left in during the refactoring shuffle from PR #8205, and causes an issue in a corner case where an LTI launch provides an instance GUID where there wasn't one already set for the consumer. This change fixes the bug, and adds a test to prevent it from recurring. --- lms/djangoapps/lti_provider/models.py | 1 - lms/djangoapps/lti_provider/tests/test_views.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/lti_provider/models.py b/lms/djangoapps/lti_provider/models.py index 42cb2d4e76..75ecc2172f 100644 --- a/lms/djangoapps/lti_provider/models.py +++ b/lms/djangoapps/lti_provider/models.py @@ -62,7 +62,6 @@ class LtiConsumer(models.Model): if not consumer: consumer = LtiConsumer.objects.get( consumer_key=consumer_key, - instance_guid=instance_guid if instance_guid else None ) # Add the instance_guid field to the model if it's not there already. diff --git a/lms/djangoapps/lti_provider/tests/test_views.py b/lms/djangoapps/lti_provider/tests/test_views.py index eb1cbe851e..e2466a5f59 100644 --- a/lms/djangoapps/lti_provider/tests/test_views.py +++ b/lms/djangoapps/lti_provider/tests/test_views.py @@ -257,6 +257,17 @@ class LtiRunTest(TestCase): views.lti_run(request) self.assertNotIn(views.LTI_SESSION_KEY, request.session) + @patch('lti_provider.views.render_courseware') + 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') + class RenderCoursewareTest(TestCase): """