def test_preprocess_collection_with_disabled_tabs(self, ): """ Tests that preprocess collection returns correct data if `course_structure` and `tags` are disabled. """ initial_collection = [ { u"quote": u"quote text1", u"text": u"text1", u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2016, 01, 26, 8, 5, 16, 00000).isoformat(), }, { u"quote": u"quote text2", u"text": u"text2", u"usage_id": unicode(self.html_module_2.location), u"updated": datetime(2016, 01, 26, 9, 6, 17, 00000).isoformat(), }, ] self.assertItemsEqual( [ { 'section': {}, 'chapter': {}, "unit": { u"url": self._get_unit_url(self.course, self.chapter, self.sequential), u"display_name": self.vertical.display_name_with_default_escaped, u"location": unicode(self.vertical.location), }, u'text': u'text1', u'quote': u'quote text1', u'usage_id': unicode(self.html_module_1.location), u'updated': datetime(2016, 01, 26, 8, 5, 16) }, { 'section': {}, 'chapter': {}, "unit": { u"url": self._get_unit_url(self.course, self.chapter, self.sequential), u"display_name": self.vertical.display_name_with_default_escaped, u"location": unicode(self.vertical.location), }, u'text': u'text2', u'quote': u'quote text2', u'usage_id': unicode(self.html_module_2.location), u'updated': datetime(2016, 01, 26, 9, 6, 17) } ], helpers.preprocess_collection(self.user, self.course, initial_collection) )
def test_preprocess_collection_no_item(self): """ Tests the result if appropriate module is not found. """ initial_collection = [ { u"quote": u"quote text", u"text": u"text", u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000).isoformat() }, { u"quote": u"quote text", u"text": u"text", u"usage_id": unicode(self.course.id.make_usage_key("html", "test_item")), u"updated": datetime(2014, 11, 19, 8, 6, 16, 00000).isoformat() }, ] self.assertItemsEqual( [{ u"quote": u"quote text", u"text": u"text", u"chapter": { u"display_name": self.chapter.display_name_with_default, u"index": 0, u"location": unicode(self.chapter.location), u"children": [unicode(self.sequential.location)] }, u"section": { u"display_name": self.sequential.display_name_with_default, u"location": unicode(self.sequential.location), u"children": [ unicode(self.vertical.location), unicode(self.vertical_with_container.location) ] }, u"unit": { u"url": self._get_unit_url(self.course, self.chapter, self.sequential), u"display_name": self.vertical.display_name_with_default, u"location": unicode(self.vertical.location), }, u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000), }], helpers.preprocess_collection(self.user, self.course, initial_collection))
def test_preprocess_collection_has_access(self): """ Tests the result if the user does not have access to some of the modules. """ initial_collection = [ { u"quote": u"quote text", u"text": u"text", u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000).isoformat(), }, { u"quote": u"quote text", u"text": u"text", u"usage_id": unicode(self.html_module_2.location), u"updated": datetime(2014, 11, 19, 8, 6, 16, 00000).isoformat(), }, ] self.html_module_2.visible_to_staff_only = True self.store.update_item(self.html_module_2, self.user.id) self.assertItemsEqual( [{ u"quote": u"quote text", u"text": u"text", u"chapter": { u"display_name": self.chapter.display_name_with_default, u"index": 0, u"location": unicode(self.chapter.location), u"children": [unicode(self.sequential.location)] }, u"section": { u"display_name": self.sequential.display_name_with_default, u"location": unicode(self.sequential.location), u"children": [ unicode(self.vertical.location), unicode(self.vertical_with_container.location) ] }, u"unit": { u"url": self._get_unit_url(self.course, self.chapter, self.sequential), u"display_name": self.vertical.display_name_with_default, u"location": unicode(self.vertical.location), }, u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000), }], helpers.preprocess_collection(self.user, self.course, initial_collection))
def test_preprocess_collection_escaping(self): """ Tests the result if appropriate module is not found. """ initial_collection = [{ u"quote": u"test <script>alert('test')</script>", u"text": u"text \"<>&'", u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000).isoformat() }] self.assertItemsEqual( [{ u"quote": u"test <script>alert('test')</script>", u"text": u'text "<>&\'', u"chapter": { u"display_name": self.chapter.display_name_with_default, u"index": 0, u"location": unicode(self.chapter.location), u"children": [unicode(self.sequential.location)] }, u"section": { u"display_name": self.sequential.display_name_with_default, u"location": unicode(self.sequential.location), u"children": [ unicode(self.vertical.location), unicode(self.vertical_with_container.location) ] }, u"unit": { u"url": self._get_unit_url(self.course, self.chapter, self.sequential), u"display_name": self.vertical.display_name_with_default, u"location": unicode(self.vertical.location), }, u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000), }], helpers.preprocess_collection(self.user, self.course, initial_collection))
def test_preprocess_collection_has_access(self): """ Tests the result if the user does not have access to some of the modules. """ initial_collection = [ { u"quote": u"quote text", u"text": u"text", u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000).isoformat(), }, { u"quote": u"quote text", u"text": u"text", u"usage_id": unicode(self.html_module_2.location), u"updated": datetime(2014, 11, 19, 8, 6, 16, 00000).isoformat(), }, ] self.html_module_2.visible_to_staff_only = True self.store.update_item(self.html_module_2, self.user.id) self.assertItemsEqual( [ { u"quote": u"quote text", u"text": u"text", u"chapter": { u"display_name": self.chapter.display_name_with_default, u"index": 0, u"location": unicode(self.chapter.location), u"children": [unicode(self.sequential.location)], }, u"section": { u"display_name": self.sequential.display_name_with_default, u"location": unicode(self.sequential.location), u"children": [unicode(self.vertical.location), unicode(self.vertical_with_container.location)], }, u"unit": { u"url": self._get_unit_url(self.course, self.chapter, self.sequential), u"display_name": self.vertical.display_name_with_default, u"location": unicode(self.vertical.location), }, u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000), } ], helpers.preprocess_collection(self.user, self.course, initial_collection), )
def test_preprocess_collection_no_item(self): """ Tests the result if appropriate module is not found. """ initial_collection = [ { u"quote": u"quote text", u"text": u"text", u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000).isoformat(), }, { u"quote": u"quote text", u"text": u"text", u"usage_id": unicode(self.course.id.make_usage_key("html", "test_item")), u"updated": datetime(2014, 11, 19, 8, 6, 16, 00000).isoformat(), }, ] self.assertItemsEqual( [ { u"quote": u"quote text", u"text": u"text", u"chapter": { u"display_name": self.chapter.display_name_with_default, u"index": 0, u"location": unicode(self.chapter.location), u"children": [unicode(self.sequential.location)], }, u"section": { u"display_name": self.sequential.display_name_with_default, u"location": unicode(self.sequential.location), u"children": [unicode(self.vertical.location), unicode(self.vertical_with_container.location)], }, u"unit": { u"url": self._get_unit_url(self.course, self.chapter, self.sequential), u"display_name": self.vertical.display_name_with_default, u"location": unicode(self.vertical.location), }, u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000), } ], helpers.preprocess_collection(self.user, self.course, initial_collection), )
def test_preprocess_collection_no_unit(self, mock_modulestore, mock_has_access): """ Tests the result if the unit does not exist. """ store = MagicMock() store.get_item().get_parent.return_value = None mock_modulestore.return_value = store mock_has_access.return_value = True initial_collection = [{ u"quote": u"quote text", u"text": u"text", u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000).isoformat(), }] self.assertItemsEqual( [], helpers.preprocess_collection(self.user, self.course, initial_collection) )
def test_preprocess_collection_escaping(self): """ Tests the result if appropriate module is not found. """ initial_collection = [ { u"quote": u"test <script>alert('test')</script>", u"text": u"text \"<>&'", u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000).isoformat(), } ] self.assertItemsEqual( [ { u"quote": u"test <script>alert('test')</script>", u"text": u"text \"<>&'", u"chapter": { u"display_name": self.chapter.display_name_with_default, u"index": 0, u"location": unicode(self.chapter.location), u"children": [unicode(self.sequential.location)], }, u"section": { u"display_name": self.sequential.display_name_with_default, u"location": unicode(self.sequential.location), u"children": [unicode(self.vertical.location), unicode(self.vertical_with_container.location)], }, u"unit": { u"url": self._get_unit_url(self.course, self.chapter, self.sequential), u"display_name": self.vertical.display_name_with_default, u"location": unicode(self.vertical.location), }, u"usage_id": unicode(self.html_module_1.location), u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000), } ], helpers.preprocess_collection(self.user, self.course, initial_collection), )