From 99ded6c7ee65744190bfd976a3a32d0919b79346 Mon Sep 17 00:00:00 2001 From: John Eskew Date: Tue, 22 Dec 2015 11:25:52 -0500 Subject: [PATCH] Import test course instead of using XML-backed course. --- lms/djangoapps/courseware/tests/test_about.py | 32 +++++++++++---- .../courseware/tests/test_course_info.py | 36 ++++++++++++----- .../courseware/tests/test_courses.py | 16 ++++++-- lms/djangoapps/courseware/tests/test_tabs.py | 40 ++++++++++++++----- 4 files changed, 93 insertions(+), 31 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_about.py b/lms/djangoapps/courseware/tests/test_about.py index 3ed5e67c39..1bed645f5d 100644 --- a/lms/djangoapps/courseware/tests/test_about.py +++ b/lms/djangoapps/courseware/tests/test_about.py @@ -15,6 +15,8 @@ from opaque_keys.edx.locations import SlashSeparatedCourseKey from course_modes.models import CourseMode from track.tests import EventTrackingTestCase from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_CLOSED_MODULESTORE +from xmodule.modulestore.tests.utils import TEST_DATA_DIR +from xmodule.modulestore.xml_importer import import_course_from_xml from student.models import CourseEnrollment from student.tests.factories import AdminFactory, CourseEnrollmentAllowedFactory, UserFactory @@ -201,14 +203,30 @@ class AboutTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): """ MODULESTORE = TEST_DATA_MIXED_CLOSED_MODULESTORE - # The following XML test course (which lives at common/test/data/2014) - # is closed; we're testing that an about page still appears when - # the course is already closed - xml_course_id = SlashSeparatedCourseKey('edX', 'detached_pages', '2014') + def setUp(self): + """ + Set up the tests + """ + super(AboutTestCaseXML, self).setUp() - # this text appears in that course's about page - # common/test/data/2014/about/overview.html - xml_data = "about page 463139" + # The following test course (which lives at common/test/data/2014) + # is closed; we're testing that an about page still appears when + # the course is already closed + self.xml_course_id = self.store.make_course_key('edX', 'detached_pages', '2014') + import_course_from_xml( + self.store, + 'test_user', + TEST_DATA_DIR, + source_dirs=['2014'], + static_content_store=None, + target_id=self.xml_course_id, + raise_on_failure=True, + create_if_not_present=True, + ) + + # this text appears in that course's about page + # common/test/data/2014/about/overview.html + self.xml_data = "about page 463139" @patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_logged_in_xml(self): diff --git a/lms/djangoapps/courseware/tests/test_course_info.py b/lms/djangoapps/courseware/tests/test_course_info.py index f71db15908..99f34a3c84 100644 --- a/lms/djangoapps/courseware/tests/test_course_info.py +++ b/lms/djangoapps/courseware/tests/test_course_info.py @@ -17,9 +17,11 @@ from util.date_utils import strftime_localized from xmodule.modulestore.tests.django_utils import ( ModuleStoreTestCase, SharedModuleStoreTestCase, - TEST_DATA_SPLIT_MODULESTORE + TEST_DATA_SPLIT_MODULESTORE, + TEST_DATA_MIXED_CLOSED_MODULESTORE ) -from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_CLOSED_MODULESTORE +from xmodule.modulestore.tests.utils import TEST_DATA_DIR +from xmodule.modulestore.xml_importer import import_course_from_xml from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls from student.models import CourseEnrollment from student.tests.factories import AdminFactory @@ -214,14 +216,30 @@ class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): """ MODULESTORE = TEST_DATA_MIXED_CLOSED_MODULESTORE - # The following XML test course (which lives at common/test/data/2014) - # is closed; we're testing that a course info page still appears when - # the course is already closed - xml_course_key = SlashSeparatedCourseKey('edX', 'detached_pages', '2014') + def setUp(self): + """ + Set up the tests + """ + super(CourseInfoTestCaseXML, self).setUp() - # this text appears in that course's course info page - # common/test/data/2014/info/updates.html - xml_data = "course info 463139" + # The following test course (which lives at common/test/data/2014) + # is closed; we're testing that a course info page still appears when + # the course is already closed + self.xml_course_key = self.store.make_course_key('edX', 'detached_pages', '2014') + import_course_from_xml( + self.store, + 'test_user', + TEST_DATA_DIR, + source_dirs=['2014'], + static_content_store=None, + target_id=self.xml_course_key, + raise_on_failure=True, + create_if_not_present=True, + ) + + # this text appears in that course's course info page + # common/test/data/2014/info/updates.html + self.xml_data = "course info 463139" @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_logged_in_xml(self): diff --git a/lms/djangoapps/courseware/tests/test_courses.py b/lms/djangoapps/courseware/tests/test_courses.py index 32788027a6..fde9442fb3 100644 --- a/lms/djangoapps/courseware/tests/test_courses.py +++ b/lms/djangoapps/courseware/tests/test_courses.py @@ -32,9 +32,12 @@ from student.tests.factories import UserFactory from xmodule.modulestore.django import _get_modulestore_branch_setting, modulestore from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.xml_importer import import_course_from_xml -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_TOY_MODULESTORE -from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, check_mongo_calls +from xmodule.modulestore.tests.django_utils import ( + ModuleStoreTestCase, TEST_DATA_MIXED_TOY_MODULESTORE +) +from xmodule.modulestore.tests.factories import ( + CourseFactory, ItemFactory, ToyCourseFactory, check_mongo_calls +) from xmodule.tests.xml import factories as xml from xmodule.tests.xml import XModuleXmlImportTest @@ -308,7 +311,12 @@ class XmlCoursesRenderTest(ModuleStoreTestCase): """Test methods related to rendering courses content for an XML course.""" MODULESTORE = TEST_DATA_MIXED_TOY_MODULESTORE - toy_course_key = SlashSeparatedCourseKey('edX', 'toy', '2012_Fall') + def setUp(self): + """ + Make sure that course is reloaded every time--clear out the modulestore. + """ + super(XmlCoursesRenderTest, self).setUp() + self.toy_course_key = ToyCourseFactory.create().id def test_get_course_info_section_render(self): course = get_course_by_id(self.toy_course_key) diff --git a/lms/djangoapps/courseware/tests/test_tabs.py b/lms/djangoapps/courseware/tests/test_tabs.py index d94de34be5..abc34a64fb 100644 --- a/lms/djangoapps/courseware/tests/test_tabs.py +++ b/lms/djangoapps/courseware/tests/test_tabs.py @@ -27,10 +27,12 @@ from util.milestones_helpers import ( from milestones.tests.utils import MilestonesTestCaseMixin from xmodule import tabs as xmodule_tabs from xmodule.modulestore.tests.django_utils import ( - TEST_DATA_MIXED_TOY_MODULESTORE, TEST_DATA_MIXED_CLOSED_MODULESTORE, - SharedModuleStoreTestCase) -from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase + ModuleStoreTestCase, + SharedModuleStoreTestCase +) from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.modulestore.tests.utils import TEST_DATA_DIR +from xmodule.modulestore.xml_importer import import_course_from_xml class TabTestCase(SharedModuleStoreTestCase): @@ -289,15 +291,31 @@ class StaticTabDateTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase): MODULESTORE = TEST_DATA_MIXED_CLOSED_MODULESTORE - # The following XML test course (which lives at common/test/data/2014) - # is closed; we're testing that tabs still appear when - # the course is already closed - xml_course_key = SlashSeparatedCourseKey('edX', 'detached_pages', '2014') + def setUp(self): + """ + Set up the tests + """ + super(StaticTabDateTestCaseXML, self).setUp() - # this text appears in the test course's tab - # common/test/data/2014/tabs/8e4cce2b4aaf4ba28b1220804619e41f.html - xml_data = "static 463139" - xml_url = "8e4cce2b4aaf4ba28b1220804619e41f" + # The following XML test course (which lives at common/test/data/2014) + # is closed; we're testing that tabs still appear when + # the course is already closed + self.xml_course_key = self.store.make_course_key('edX', 'detached_pages', '2014') + import_course_from_xml( + self.store, + 'test_user', + TEST_DATA_DIR, + source_dirs=['2014'], + static_content_store=None, + target_id=self.xml_course_key, + raise_on_failure=True, + create_if_not_present=True, + ) + + # this text appears in the test course's tab + # common/test/data/2014/tabs/8e4cce2b4aaf4ba28b1220804619e41f.html + self.xml_data = "static 463139" + self.xml_url = "8e4cce2b4aaf4ba28b1220804619e41f" @patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) def test_logged_in_xml(self):