From 85b3a7ae68401e98d3b65bfc0f829631839bbad5 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Khalid <ahmedbilal96@gmail.com> Date: Fri, 17 Jul 2020 00:31:01 +0500 Subject: [PATCH] Make Lti Consumer indexable --- lti_consumer/lti_xblock.py | 23 +++++++++++++++++++ lti_consumer/tests/unit/test_lti_xblock.py | 26 ++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lti_consumer/lti_xblock.py b/lti_consumer/lti_xblock.py index 2c85e8c..ea5d3fe 100644 --- a/lti_consumer/lti_xblock.py +++ b/lti_consumer/lti_xblock.py @@ -1471,3 +1471,26 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock): 'lti_2_0_result_rest_handler': 'result_service_url' } return getattr(self, mapping[service_name]) + + def index_dictionary(self): + """ + Return dictionary prepared with module content and type for indexing. + """ + # return key/value fields in a Python dict object + # values may be numeric / string or dict + # default implementation is an empty dict + xblock_body = super(LtiConsumerXBlock, self).index_dictionary() + + index_body = { + "display_name": self.display_name, + "description": self.description, + } + + if "content" in xblock_body: + xblock_body["content"].update(index_body) + else: + xblock_body["content"] = index_body + + xblock_body["content_type"] = "LTI Consumer" + + return xblock_body diff --git a/lti_consumer/tests/unit/test_lti_xblock.py b/lti_consumer/tests/unit/test_lti_xblock.py index 4eca499..29124a9 100644 --- a/lti_consumer/tests/unit/test_lti_xblock.py +++ b/lti_consumer/tests/unit/test_lti_xblock.py @@ -42,6 +42,32 @@ class TestLtiConsumerXBlock(TestCase): self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock, self.xblock_attributes) +class TestIndexibility(TestCase): + """ + Test indexibility of Lti Consumer XBlock + """ + def setUp(self): + super(TestIndexibility, self).setUp() + self.xblock_attributes = { + 'launch_url': 'http://www.example.com', + 'display_name': 'Example LTI Consumer Application', + 'description': 'An example application to demonstrate LTI Consumer' + } + self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock, self.xblock_attributes) + + def test_indexibility(self): + self.assertEqual( + self.xblock.index_dictionary(), + { + 'content_type': 'LTI Consumer', + 'content': { + 'display_name': 'Example LTI Consumer Application', + 'description': 'An example application to demonstrate LTI Consumer' + } + } + ) + + class TestProperties(TestLtiConsumerXBlock): """ Unit tests for LtiConsumerXBlock properties diff --git a/setup.py b/setup.py index 0940c91..74ec21a 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ with open('README.rst') as _f: setup( name='lti-consumer-xblock', - version='2.0.3', + version='2.1.0', description='This XBlock implements the consumer side of the LTI specification.', long_description=long_description, long_description_content_type='text/markdown', -- GitLab