From 3559bd1e698d9cea5d5ba127c0c65aa472bc0300 Mon Sep 17 00:00:00 2001 From: Mushtaq Ali Date: Mon, 15 Feb 2016 18:18:46 +0500 Subject: [PATCH] Refactor test to check support for both modulestore and is_self_paced method improvement --- cms/djangoapps/contentstore/utils.py | 2 +- .../contentstore/views/tests/test_item.py | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 9c10a00516..03a2b6aae2 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -463,4 +463,4 @@ def is_self_paced(course): """ Returns True if course is self-paced, False otherwise. """ - return course.self_paced and SelfPacedConfiguration.current().enabled if course else False + return course and course.self_paced and SelfPacedConfiguration.current().enabled diff --git a/cms/djangoapps/contentstore/views/tests/test_item.py b/cms/djangoapps/contentstore/views/tests/test_item.py index 4711be650e..833c39d08c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_item.py +++ b/cms/djangoapps/contentstore/views/tests/test_item.py @@ -1848,6 +1848,7 @@ class TestLibraryXBlockCreation(ItemTest): self.assertFalse(lib.children) +@ddt.ddt class TestXBlockPublishingInfo(ItemTest): """ Unit tests for XBlock's outline handling. @@ -2171,7 +2172,8 @@ class TestXBlockPublishingInfo(ItemTest): self._verify_has_staff_only_message(xblock_info, True, path=self.FIRST_SUBSECTION_PATH) self._verify_has_staff_only_message(xblock_info, True, path=self.FIRST_UNIT_PATH) - def test_self_paced_item_visibility_state(self): + @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split) + def test_self_paced_item_visibility_state(self, store_type): """ Test that in self-paced course, item has `live` visibility state. Test that when item was initially in `scheduled` state in instructor mode, change course pacing to self-paced, @@ -2179,20 +2181,22 @@ class TestXBlockPublishingInfo(ItemTest): """ SelfPacedConfiguration(enabled=True).save() - # Create chapter and setup future release date to make chapter in scheduled state - chapter = self._create_child(self.course, 'chapter', "Test Chapter") - self._set_release_date(chapter.location, datetime.now(UTC) + timedelta(days=1)) + with self.store.default_store(store_type): + # Create course, chapter and setup future release date to make chapter in scheduled state + course = CourseFactory.create() + chapter = self._create_child(course, 'chapter', "Test Chapter") + self._set_release_date(chapter.location, datetime.now(UTC) + timedelta(days=1)) - # Check that has scheduled state - xblock_info = self._get_xblock_info(chapter.location) - self._verify_visibility_state(xblock_info, VisibilityState.ready) - self.assertFalse(self.course.self_paced) + # Check that has scheduled state + xblock_info = self._get_xblock_info(chapter.location) + self._verify_visibility_state(xblock_info, VisibilityState.ready) + self.assertFalse(course.self_paced) - # Change course pacing to self paced - self.course.self_paced = True - self.store.update_item(self.course, self.user.id) - self.assertTrue(self.course.self_paced) + # Change course pacing to self paced + course.self_paced = True + self.store.update_item(course, self.user.id) + self.assertTrue(course.self_paced) - # Check that in self paced course content has live state now - xblock_info = self._get_xblock_info(chapter.location) - self._verify_visibility_state(xblock_info, VisibilityState.live) + # Check that in self paced course content has live state now + xblock_info = self._get_xblock_info(chapter.location) + self._verify_visibility_state(xblock_info, VisibilityState.live)