Esempio n. 1
0
    def setUpClass(cls):
        super(SharedModuleStoreTestCase, cls).setUpClass()

        cls._settings_override = override_settings(MODULESTORE=cls.MODULESTORE)
        cls._settings_override.__enter__()
        XMODULE_FACTORY_LOCK.enable()
        clear_existing_modulestores()
        cls.store = modulestore()
Esempio n. 2
0
 def setUpClass(cls):
     """
     Delete the existing modulestores, causing them to be reloaded.
     """
     # Clear out any existing modulestores,
     # which will cause them to be re-created
     # the next time they are accessed.
     clear_existing_modulestores()
     TestCase.setUpClass()
Esempio n. 3
0
def clear_courses():
    # Flush and initialize the module store
    # Note that if your test module gets in some weird state
    # (though it shouldn't), do this manually
    # from the bash shell to drop it:
    # $ mongo test_xmodule --eval "db.dropDatabase()"
    modulestore()._drop_database()  # pylint: disable=protected-access
    _CONTENTSTORE.clear()
    clear_existing_modulestores()
Esempio n. 4
0
 def _setUpModuleStore(cls):  # pylint: disable=invalid-name
     """
     Set up the modulestore for an entire test class.
     """
     cls._settings_override = override_settings(MODULESTORE=cls.MODULESTORE)
     cls._settings_override.__enter__()
     XMODULE_FACTORY_LOCK.enable()
     clear_existing_modulestores()
     cls.store = modulestore()
Esempio n. 5
0
def clear_courses():
    # Flush and initialize the module store
    # Note that if your test module gets in some weird state
    # (though it shouldn't), do this manually
    # from the bash shell to drop it:
    # $ mongo test_xmodule --eval "db.dropDatabase()"
    modulestore()._drop_database()  # pylint: disable=protected-access
    _CONTENTSTORE.clear()
    clear_existing_modulestores()
Esempio n. 6
0
 def setUpClass(cls):
     """
     Delete the existing modulestores, causing them to be reloaded.
     """
     # Clear out any existing modulestores,
     # which will cause them to be re-created
     # the next time they are accessed.
     clear_existing_modulestores()
     TestCase.setUpClass()
Esempio n. 7
0
    def setUp(self):
        # Clear out the modulestores, causing them to reload
        clear_existing_modulestores()
        self.graded_course = modulestore().get_course(SlashSeparatedCourseKey("edX", "graded", "2012_Fall"))

        # Create staff account
        self.staff = StaffFactory(course_key=self.graded_course.id)

        self.logout()
        # self.staff.password is the sha hash but login takes the plain text
        self.login(self.staff.email, 'test')
        self.enroll(self.graded_course)
Esempio n. 8
0
    def setUp(self):
        # Clear out the modulestores, causing them to reload
        clear_existing_modulestores()
        self.graded_course = modulestore().get_course(SlashSeparatedCourseKey("edX", "graded", "2012_Fall"))

        # Create staff account
        self.staff = StaffFactory(course_key=self.graded_course.id)

        self.logout()
        # self.staff.password is the sha hash but login takes the plain text
        self.login(self.staff.email, 'test')
        self.enroll(self.graded_course)
Esempio n. 9
0
    def setUp(self, **kwargs):
        """
        Creates a test User if `create_user` is True.
        Returns the password for the test User.

        Args:
            create_user - specifies whether or not to create a test User.  Default is True.
        """
        settings_override = override_settings(MODULESTORE=self.MODULESTORE)
        settings_override.__enter__()
        self.addCleanup(settings_override.__exit__, None, None, None)

        # Clear out any existing modulestores,
        # which will cause them to be re-created
        clear_existing_modulestores()

        self.addCleanup(drop_mongo_collections)
        self.addCleanup(clear_all_caches)

        # Enable XModuleFactories for the space of this test (and its setUp).
        self.addCleanup(XMODULE_FACTORY_LOCK.disable)
        XMODULE_FACTORY_LOCK.enable()

        # When testing CCX, we should make sure that
        # OverrideFieldData.provider_classes is always reset to `None` so
        # that they're recalculated for every test
        OverrideFieldData.provider_classes = None

        super(ModuleStoreTestCase, self).setUp()

        SignalHandler.course_published.disconnect(
            trigger_update_xblocks_cache_task)

        self.store = modulestore()

        uname = 'testuser'
        email = '*****@*****.**'
        password = '******'

        if kwargs.pop('create_user', True):
            # Create the user so we can log them in.
            self.user = User.objects.create_user(uname, email, password)

            # Note that we do not actually need to do anything
            # for registration if we directly mark them active.
            self.user.is_active = True

            # Staff has access to view all courses
            self.user.is_staff = True
            self.user.save()

        return password
Esempio n. 10
0
    def _post_teardown(self):
        """
        Flush the ModuleStore after each test.
        """
        self.drop_mongo_collections()
        # Clear out the existing modulestores,
        # which will cause them to be re-created
        # the next time they are accessed.
        # We do this at *both* setup and teardown just to be safe.
        clear_existing_modulestores()

        # Call superclass implementation
        super(ModuleStoreTestCase, self)._post_teardown()
Esempio n. 11
0
    def _post_teardown(self):
        """
        Flush the ModuleStore after each test.
        """
        self.drop_mongo_collections()
        # Clear out the existing modulestores,
        # which will cause them to be re-created
        # the next time they are accessed.
        # We do this at *both* setup and teardown just to be safe.
        clear_existing_modulestores()

        # Call superclass implementation
        super(ModuleStoreTestCase, self)._post_teardown()
Esempio n. 12
0
    def setUp(self, **kwargs):
        """
        Creates a test User if `create_user` is True.
        Returns the password for the test User.

        Args:
            create_user - specifies whether or not to create a test User.  Default is True.
        """
        settings_override = override_settings(MODULESTORE=self.MODULESTORE)
        settings_override.__enter__()
        self.addCleanup(settings_override.__exit__, None, None, None)

        # Clear out any existing modulestores,
        # which will cause them to be re-created
        clear_existing_modulestores()

        self.addCleanup(drop_mongo_collections)
        self.addCleanup(clear_all_caches)

        # Enable XModuleFactories for the space of this test (and its setUp).
        self.addCleanup(XMODULE_FACTORY_LOCK.disable)
        XMODULE_FACTORY_LOCK.enable()

        # When testing CCX, we should make sure that
        # OverrideFieldData.provider_classes is always reset to `None` so
        # that they're recalculated for every test
        OverrideFieldData.provider_classes = None

        super(ModuleStoreTestCase, self).setUp()

        SignalHandler.course_published.disconnect(trigger_update_xblocks_cache_task)

        self.store = modulestore()

        uname = 'testuser'
        email = '*****@*****.**'
        password = '******'

        if kwargs.pop('create_user', True):
            # Create the user so we can log them in.
            self.user = User.objects.create_user(uname, email, password)

            # Note that we do not actually need to do anything
            # for registration if we directly mark them active.
            self.user.is_active = True

            # Staff has access to view all courses
            self.user.is_staff = True
            self.user.save()

        return password
Esempio n. 13
0
    def tearDownClass(cls):
        """
        Drop the existing modulestores, causing them to be reloaded.
        Clean up any data stored in Mongo.
        """
        # Clean up by flushing the Mongo modulestore
        cls.drop_mongo_collections()

        # Clear out the existing modulestores,
        # which will cause them to be re-created
        # the next time they are accessed.
        # We do this at *both* setup and teardown just to be safe.
        clear_existing_modulestores()

        TestCase.tearDownClass()
Esempio n. 14
0
    def tearDownClass(cls):
        """
        Drop the existing modulestores, causing them to be reloaded.
        Clean up any data stored in Mongo.
        """
        # Clean up by flushing the Mongo modulestore
        cls.drop_mongo_collections()

        # Clear out the existing modulestores,
        # which will cause them to be re-created
        # the next time they are accessed.
        # We do this at *both* setup and teardown just to be safe.
        clear_existing_modulestores()

        TestCase.tearDownClass()
Esempio n. 15
0
    def start_modulestore_isolation(cls):
        """
        Isolate uses of the modulestore after this call. Once
        :py:meth:`end_modulestore_isolation` is called, this modulestore will
        be flushed (all content will be deleted).
        """
        cls.start_cache_isolation()
        override = override_settings(
            MODULESTORE=cls.MODULESTORE,
        )

        cls.__old_modulestores.append(copy.deepcopy(settings.MODULESTORE))
        override.__enter__()
        cls.__settings_overrides.append(override)
        XMODULE_FACTORY_LOCK.enable()
        clear_existing_modulestores()
        cls.store = modulestore()
Esempio n. 16
0
    def setUp(self, **kwargs):
        """
        Creates a test User if `create_user` is True.
        Returns the password for the test User.

        Args:
            create_user - specifies whether or not to create a test User.  Default is True.
        """
        settings_override = override_settings(MODULESTORE=self.MODULESTORE)
        settings_override.__enter__()
        self.addCleanup(settings_override.__exit__, None, None, None)

        # Clear out any existing modulestores,
        # which will cause them to be re-created
        clear_existing_modulestores()

        self.addCleanup(self.drop_mongo_collections)

        self.addCleanup(RequestCache().clear_request_cache)

        # Enable XModuleFactories for the space of this test (and its setUp).
        self.addCleanup(XMODULE_FACTORY_LOCK.disable)
        XMODULE_FACTORY_LOCK.enable()

        super(ModuleStoreTestCase, self).setUp()

        self.store = modulestore()

        uname = 'testuser'
        email = '*****@*****.**'
        password = '******'

        if kwargs.pop('create_user', True):
            # Create the user so we can log them in.
            self.user = User.objects.create_user(uname, email, password)

            # Note that we do not actually need to do anything
            # for registration if we directly mark them active.
            self.user.is_active = True

            # Staff has access to view all courses
            self.user.is_staff = True
            self.user.save()

        return password
Esempio n. 17
0
    def setUp(self, **kwargs):
        """
        Creates a test User if `create_user` is True.
        Returns the password for the test User.

        Args:
            create_user - specifies whether or not to create a test User.  Default is True.
        """
        settings_override = override_settings(MODULESTORE=self.MODULESTORE)
        settings_override.__enter__()
        self.addCleanup(settings_override.__exit__, None, None, None)

        # Clear out any existing modulestores,
        # which will cause them to be re-created
        clear_existing_modulestores()

        self.addCleanup(self.drop_mongo_collections)

        self.addCleanup(RequestCache().clear_request_cache)

        # Enable XModuleFactories for the space of this test (and its setUp).
        self.addCleanup(XMODULE_FACTORY_LOCK.disable)
        XMODULE_FACTORY_LOCK.enable()

        super(ModuleStoreTestCase, self).setUp()

        self.store = modulestore()

        uname = 'testuser'
        email = '*****@*****.**'
        password = '******'

        if kwargs.pop('create_user', True):
            # Create the user so we can log them in.
            self.user = User.objects.create_user(uname, email, password)

            # Note that we do not actually need to do anything
            # for registration if we directly mark them active.
            self.user.is_active = True

            # Staff has access to view all courses
            self.user.is_staff = True
            self.user.save()

        return password
    def setUp(self):
        clear_existing_modulestores()
        self.toy = modulestore().get_course("edX/toy/2012_Fall")

        # Create two accounts
        self.student = '*****@*****.**'
        self.instructor = '*****@*****.**'
        self.password = '******'
        self.create_account('u1', self.student, self.password)
        self.create_account('u2', self.instructor, self.password)
        self.activate_user(self.student)
        self.activate_user(self.instructor)

        CourseStaffRole(self.toy.location).add_users(User.objects.get(email=self.instructor))

        self.logout()
        self.login(self.instructor, self.password)
        self.enroll(self.toy)
    def setUp(self):
        clear_existing_modulestores()
        self.toy = modulestore().get_course(SlashSeparatedCourseKey("edX", "toy", "2012_Fall"))

        # Create two accounts
        self.student = '*****@*****.**'
        self.instructor = '*****@*****.**'
        self.password = '******'
        self.create_account('u1', self.student, self.password)
        self.create_account('u2', self.instructor, self.password)
        self.activate_user(self.student)
        self.activate_user(self.instructor)

        CourseStaffRole(self.toy.id).add_users(User.objects.get(email=self.instructor))

        self.logout()
        self.login(self.instructor, self.password)
        self.enroll(self.toy)
Esempio n. 20
0
    def start_modulestore_isolation(cls):
        """
        Isolate uses of the modulestore after this call. Once
        :py:meth:`end_modulestore_isolation` is called, this modulestore will
        be flushed (all content will be deleted).
        """
        cls.start_cache_isolation()
        override = override_settings(
            MODULESTORE=cls.MODULESTORE(),
            CONTENTSTORE=cls.CONTENTSTORE(),
        )

        cls.__old_modulestores.append(copy.deepcopy(settings.MODULESTORE))
        cls.__old_contentstores.append(copy.deepcopy(settings.CONTENTSTORE))
        override.__enter__()
        cls.__settings_overrides.append(override)
        XMODULE_FACTORY_LOCK.enable()
        clear_existing_modulestores()
        cls.store = modulestore()
    def setUp(self):

        # Clear out the modulestores, causing them to reload
        clear_existing_modulestores()

        self.graded_course = modulestore().get_course("edX/graded/2012_Fall")

        # Create staff account
        self.instructor = '*****@*****.**'
        self.password = '******'
        self.create_account('u2', self.instructor, self.password)
        self.activate_user(self.instructor)

        def make_instructor(course):
            CourseStaffRole(course.location).add_users(User.objects.get(email=self.instructor))

        make_instructor(self.graded_course)

        self.logout()
        self.login(self.instructor, self.password)
        self.enroll(self.graded_course)
Esempio n. 22
0
    def start_modulestore_isolation(cls):
        """
        Isolate uses of the modulestore after this call. Once
        :py:meth:`end_modulestore_isolation` is called, this modulestore will
        be flushed (all content will be deleted).
        """
        cls.disable_all_signals()
        cls.enable_signals_by_name(*cls.ENABLED_SIGNALS)
        cls.start_cache_isolation()
        override = override_settings(
            MODULESTORE=cls.MODULESTORE(),
            CONTENTSTORE=cls.CONTENTSTORE(),
        )

        cls.__old_modulestores.append(copy.deepcopy(settings.MODULESTORE))
        cls.__old_contentstores.append(copy.deepcopy(settings.CONTENTSTORE))
        override.__enter__()
        cls.__settings_overrides.append(override)
        XMODULE_FACTORY_LOCK.enable()
        clear_existing_modulestores()
        cls.store = modulestore()
    def setUp(self):
        clear_existing_modulestores()
        courses = modulestore().get_courses()

        self.course_id = "edX/toy/2012_Fall"
        self.toy = modulestore().get_course(self.course_id)

        # Create two accounts
        self.student = '*****@*****.**'
        self.instructor = '*****@*****.**'
        self.password = '******'
        self.create_account('u1', self.student, self.password)
        self.create_account('u2', self.instructor, self.password)
        self.activate_user(self.student)
        self.activate_user(self.instructor)

        CourseStaffRole(self.toy.location).add_users(User.objects.get(email=self.instructor))

        self.logout()
        self.login(self.instructor, self.password)
        self.enroll(self.toy)
Esempio n. 24
0
    def setUp(self):

        # Clear out the modulestores, causing them to reload
        clear_existing_modulestores()

        self.graded_course = modulestore().get_course("edX/graded/2012_Fall")

        # Create staff account
        self.instructor = '*****@*****.**'
        self.password = '******'
        self.create_account('u2', self.instructor, self.password)
        self.activate_user(self.instructor)

        def make_instructor(course):
            CourseStaffRole(course.location).add_users(
                User.objects.get(email=self.instructor))

        make_instructor(self.graded_course)

        self.logout()
        self.login(self.instructor, self.password)
        self.enroll(self.graded_course)
Esempio n. 25
0
    def setUp(self):
        clear_existing_modulestores()
        courses = modulestore().get_courses()

        self.course_id = "edX/toy/2012_Fall"
        self.toy = modulestore().get_course(self.course_id)

        # Create two accounts
        self.student = '*****@*****.**'
        self.instructor = '*****@*****.**'
        self.password = '******'
        self.create_account('u1', self.student, self.password)
        self.create_account('u2', self.instructor, self.password)
        self.activate_user(self.student)
        self.activate_user(self.instructor)

        group_name = _course_staff_group_name(self.toy.location)
        g = Group.objects.create(name=group_name)
        g.user_set.add(User.objects.get(email=self.instructor))

        self.logout()
        self.login(self.instructor, self.password)
        self.enroll(self.toy)
    def setUp(self):
        clear_existing_modulestores()
        self.toy = modulestore().get_course("edX/toy/2012_Fall")

        # Create two accounts
        self.student = '*****@*****.**'
        self.instructor = '*****@*****.**'
        self.password = '******'
        self.create_account('u1', self.student, self.password)
        self.create_account('u2', self.instructor, self.password)
        self.activate_user(self.student)
        self.activate_user(self.instructor)

        def make_instructor(course):
            """ Create an instructor for the course. """
            group_name = _course_staff_group_name(course.location)
            group = Group.objects.create(name=group_name)
            group.user_set.add(User.objects.get(email=self.instructor))

        make_instructor(self.toy)

        self.logout()
        self.login(self.instructor, self.password)
        self.enroll(self.toy)
Esempio n. 27
0
    def verify_due_date(self, request, get_text):
        """
        Verifies that due dates are formatted properly in text returned by get_text function.
        """
        def set_show_timezone(show_timezone):
            """
            Sets the show_timezone property and returns value from get_text function.

            Note that show_timezone is deprecated and cannot be set by the user.
            """
            course.show_timezone = show_timezone
            course.save()
            return get_text()

        def set_due_date_format(due_date_format):
            """
            Sets the due_date_display_format property and returns value from get_text function.
            """
            course.due_date_display_format = due_date_format
            course.save()
            return get_text()

        request.user = self.user
        # Clear out the modulestores, so we start with the test course in its default state.
        clear_existing_modulestores()
        course = modulestore().get_course("edX/due_date/2013_fall")

        time_with_utc = "due Sep 18, 2013 at 11:30 UTC"
        time_without_utc = "due Sep 18, 2013 at 11:30"

        # The test course being used has show_timezone = False in the policy file
        # (and no due_date_display_format set). This is to test our backwards compatibility--
        # in course_module's init method, the date_display_format will be set accordingly to
        # remove the timezone.
        text = get_text()
        self.assertIn(time_without_utc, text)
        self.assertNotIn(time_with_utc, text)
        # Test that show_timezone has been cleared (which means you get the default value of True).
        self.assertTrue(course.show_timezone)

        # Clear out the due date format and verify you get the default (with timezone).
        delattr(course, 'due_date_display_format')
        course.save()
        text = get_text()
        self.assertIn(time_with_utc, text)

        # Same for setting the due date to None
        text = set_due_date_format(None)
        self.assertIn(time_with_utc, text)

        # plain text due date
        text = set_due_date_format("foobar")
        self.assertNotIn(time_with_utc, text)
        self.assertIn("due foobar", text)

        # due date with no time
        text = set_due_date_format(u"%b %d %y")
        self.assertNotIn(time_with_utc, text)
        self.assertIn("due Sep 18 13", text)

        # hide due date completely
        text = set_due_date_format(u"")
        self.assertNotIn("due ", text)

        # improperly formatted due_date_display_format falls through to default
        # (value of show_timezone does not matter-- setting to False to make that clear).
        set_show_timezone(False)
        text = set_due_date_format(u"%%%")
        self.assertNotIn("%%%", text)
        self.assertIn(time_with_utc, text)
Esempio n. 28
0
    def verify_due_date(self, request, get_text):
        """
        Verifies that due dates are formatted properly in text returned by get_text function.
        """

        def set_show_timezone(show_timezone):
            """
            Sets the show_timezone property and returns value from get_text function.

            Note that show_timezone is deprecated and cannot be set by the user.
            """
            course.show_timezone = show_timezone
            course.save()
            return get_text()

        def set_due_date_format(due_date_format):
            """
            Sets the due_date_display_format property and returns value from get_text function.
            """
            course.due_date_display_format = due_date_format
            course.save()
            return get_text()

        request.user = self.user
        # Clear out the modulestores, so we start with the test course in its default state.
        clear_existing_modulestores()
        course = modulestore().get_course("edX/due_date/2013_fall")

        time_with_utc = "due Sep 18, 2013 at 11:30 UTC"
        time_without_utc = "due Sep 18, 2013 at 11:30"

        # The test course being used has show_timezone = False in the policy file
        # (and no due_date_display_format set). This is to test our backwards compatibility--
        # in course_module's init method, the date_display_format will be set accordingly to
        # remove the timezone.
        text = get_text()
        self.assertIn(time_without_utc, text)
        self.assertNotIn(time_with_utc, text)
        # Test that show_timezone has been cleared (which means you get the default value of True).
        self.assertTrue(course.show_timezone)

        # Clear out the due date format and verify you get the default (with timezone).
        delattr(course, "due_date_display_format")
        course.save()
        text = get_text()
        self.assertIn(time_with_utc, text)

        # Same for setting the due date to None
        text = set_due_date_format(None)
        self.assertIn(time_with_utc, text)

        # plain text due date
        text = set_due_date_format("foobar")
        self.assertNotIn(time_with_utc, text)
        self.assertIn("due foobar", text)

        # due date with no time
        text = set_due_date_format(u"%b %d %y")
        self.assertNotIn(time_with_utc, text)
        self.assertIn("due Sep 18 13", text)

        # hide due date completely
        text = set_due_date_format(u"")
        self.assertNotIn("due ", text)

        # improperly formatted due_date_display_format falls through to default
        # (value of show_timezone does not matter-- setting to False to make that clear).
        set_show_timezone(False)
        text = set_due_date_format(u"%%%")
        self.assertNotIn("%%%", text)
        self.assertIn(time_with_utc, text)
Esempio n. 29
0
 def setUp(self):
     """
     Make sure that course is reloaded every time--clear out the modulestore.
     """
     clear_existing_modulestores()
     self.toy_course_key = SlashSeparatedCourseKey("edX", "toy", "2012_Fall")
Esempio n. 30
0
 def setUp(self):
     clear_existing_modulestores(
     )  # redundant w/ cleanup but someone was getting errors
     self.addCleanup(ModuleStoreTestCase.drop_mongo_collections, 'split')
     self.addCleanup(clear_existing_modulestores)
Esempio n. 31
0
 def setUp(self):
     clear_existing_modulestores()
Esempio n. 32
0
 def setUp(self):
     """
     Make sure that course is reloaded every time--clear out the modulestore.
     """
     clear_existing_modulestores()
Esempio n. 33
0
 def setUp(self):
     clear_existing_modulestores()
Esempio n. 34
0
 def setUp(self):
     """
     Make sure that course is reloaded every time--clear out the modulestore.
     """
     clear_existing_modulestores()
     self.toy_course_key = SlashSeparatedCourseKey("edX", "toy", "2012_Fall")
Esempio n. 35
0
 def setUp(self):
     clear_existing_modulestores()  # redundant w/ cleanup but someone was getting errors
     self.addCleanup(ModuleStoreTestCase.drop_mongo_collections, ModuleStoreEnum.Type.split)
     self.addCleanup(clear_existing_modulestores)
     self.split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
Esempio n. 36
0
 def setUp(self):
     super(TemplateTests, self).setUp()
     clear_existing_modulestores()  # redundant w/ cleanup but someone was getting errors
     self.addCleanup(self._drop_mongo_collections)
     self.addCleanup(clear_existing_modulestores)
     self.split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
Esempio n. 37
0
 def setUp(self):
     """
     Make sure that course is reloaded every time--clear out the modulestore.
     """
     clear_existing_modulestores()
Esempio n. 38
0
 def setUp(self):
     clear_existing_modulestores()  # redundant w/ cleanup but someone was getting errors
     self.addCleanup(ModuleStoreTestCase.drop_mongo_collections)
     self.addCleanup(clear_existing_modulestores)
     self.split_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
Esempio n. 39
0
 def setUp(self):
     clear_existing_modulestores()  # redundant w/ cleanup but someone was getting errors
     self.addCleanup(ModuleStoreTestCase.drop_mongo_collections, "split")
     self.addCleanup(clear_existing_modulestores)
Esempio n. 40
0
 def setUp(self):
     clear_existing_modulestores()  # redundant w/ cleanup but someone was getting errors
     self.addCleanup(ModuleStoreTestCase.drop_mongo_collections, SPLIT_MONGO_MODULESTORE_TYPE)
     self.addCleanup(clear_existing_modulestores)
     self.split_store = modulestore()._get_modulestore_by_type(SPLIT_MONGO_MODULESTORE_TYPE)