diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 1aef324dfd..aebfb91126 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -77,14 +77,25 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): self.client = Client() self.client.login(username=uname, password=password) - def test_advanced_components_in_edit_unit(self): + def check_components_on_page(self, component_types, expected_types): + """ + Ensure that the right types end up on the page. + + component_types is the list of advanced components. + + expected_types is the list of elements that should appear on the page. + + expected_types and component_types should be similar, but not + exactly the same -- for example, 'videoalpha' in + component_types should cause 'Video Alpha' to be present. + """ store = modulestore('direct') import_from_xml(store, 'common/test/data/', ['simple']) course = store.get_item(Location(['i4x', 'edX', 'simple', 'course', '2012_Fall', None]), depth=None) - course.advanced_modules = ADVANCED_COMPONENT_TYPES + course.advanced_modules = component_types store.update_metadata(course.location, own_metadata(course)) @@ -94,32 +105,20 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): resp = self.client.get(reverse('edit_unit', kwargs={'location': descriptor.location.url()})) self.assertEqual(resp.status_code, 200) + for expected in expected_types: + self.assertIn(expected, resp.content) + + def test_advanced_components_in_edit_unit(self): # This could be made better, but for now let's just assert that we see the advanced modules mentioned in the page # response HTML - self.assertIn('Video Alpha', resp.content) - self.assertIn('Word cloud', resp.content) - self.assertIn('Annotation', resp.content) - self.assertIn('Open Ended Response', resp.content) - self.assertIn('Peer Grading Interface', resp.content) + self.check_components_on_page(ADVANCED_COMPONENT_TYPES, ['Video Alpha', + 'Word cloud', + 'Annotation', + 'Open Ended Response', + 'Peer Grading Interface']) def test_advanced_components_require_two_clicks(self): - store = modulestore('direct') - import_from_xml(store, 'common/test/data/', ['simple']) - - course = store.get_item(Location(['i4x', 'edX', 'simple', - 'course', '2012_Fall', None]), depth=None) - - # Just add one advanced module to make sure that it does show templates even if there's only one. - course.advanced_modules = ['videoalpha'] - - store.update_metadata(course.location, own_metadata(course)) - - descriptor = store.get_items(Location('i4x', 'edX', 'simple', 'vertical', None, None))[0] - - resp = self.client.get(reverse('edit_unit', kwargs={'location': descriptor.location.url()})) - self.assertEqual(resp.status_code, 200) - - self.assertIn('Video Alpha', resp.content) + self.check_components_on_page(['videoalpha'], ['Video Alpha']) def check_edit_unit(self, test_course_name): import_from_xml(modulestore('direct'), 'common/test/data/', [test_course_name])