From 0c9732024a83a7c62032cae4beef71cbf76d4801 Mon Sep 17 00:00:00 2001 From: Peter Fogg Date: Mon, 29 Jul 2013 11:26:25 -0400 Subject: [PATCH] Add (currently failing) test case around saving metadata. --- .../contentstore/tests/test_contentstore.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index a51110163d..b15c05b984 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -1359,3 +1359,63 @@ class ContentStoreTest(ModuleStoreTestCase): self.assertEqual(course.textbooks, fetched_course.textbooks) # is this test too strict? i.e., it requires the dicts to be == self.assertEqual(course.checklists, fetched_course.checklists) + + +class MetadataSaveTestCase(ModuleStoreTestCase): + """ + Test that metadata is correctly decached. + """ + + def setUp(self): + sample_xml = ''' + + ''' + CourseFactory.create(org='edX', course='999', display_name='Robot Super Course') + course_location = Location(['i4x', 'edX', '999', 'course', 'Robot_Super_Course', None]) + + model_data = {'data': sample_xml} + self.descriptor = ItemFactory.create(parent_location=course_location, category='video', data=model_data) + + def test_metadata_persistence(self): + """ + Test that descriptors which set metadata fields in their + constructor are correctly persisted. + """ + # We should start with a source field, from the XML's tag + self.assertIn('source', own_metadata(self.descriptor)) + attrs_to_strip = { + 'show_captions', + 'youtube_id_1_0', + 'youtube_id_0_75', + 'youtube_id_1_25', + 'youtube_id_1_5', + 'start_time', + 'end_time', + 'source', + 'track' + } + # We strip out all metadata fields to reproduce a bug where + # constructors which set their fields (e.g. Video) didn't have + # those changes persisted. So in the end we have the XML data + # in `descriptor.data`, but not in the individual fields + fields = self.descriptor.fields + for field in fields: + if field.name in attrs_to_strip: + field.delete_from(self.descriptor) + + # Assert that we correctly stripped the field + self.assertNotIn('source', own_metadata(self.descriptor)) + get_modulestore(self.descriptor.location).update_metadata( + self.descriptor.location, + own_metadata(self.descriptor) + ) + module = get_modulestore(self.descriptor.location).get_item(self.descriptor.location) + # Assert that get_item correctly sets the metadata + self.assertIn('source', own_metadata(module))