当前位置: 首页>>代码示例>>Python>>正文


Python CourseEnrollmentFactory.update_enrollment方法代码示例

本文整理汇总了Python中student.tests.factories.CourseEnrollmentFactory.update_enrollment方法的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollmentFactory.update_enrollment方法的具体用法?Python CourseEnrollmentFactory.update_enrollment怎么用?Python CourseEnrollmentFactory.update_enrollment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在student.tests.factories.CourseEnrollmentFactory的用法示例。


在下文中一共展示了CourseEnrollmentFactory.update_enrollment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestMoveToVerified

# 需要导入模块: from student.tests.factories import CourseEnrollmentFactory [as 别名]
# 或者: from student.tests.factories.CourseEnrollmentFactory import update_enrollment [as 别名]
class TestMoveToVerified(SharedModuleStoreTestCase):
    """ Tests for the post-save listener. """

    @classmethod
    def setUpClass(cls):
        super(TestMoveToVerified, cls).setUpClass()
        cls.course = CourseFactory.create()

    def setUp(self):
        super(TestMoveToVerified, self).setUp()
        self.user = UserFactory()
        # Spy on number of calls to celery task.
        celery_task_patcher = mock.patch.object(
            sync_cohort_with_mode, 'apply_async',
            mock.Mock(wraps=sync_cohort_with_mode.apply_async)
        )
        self.mocked_celery_task = celery_task_patcher.start()
        self.addCleanup(celery_task_patcher.stop)

    def _enable_cohorting(self):
        """ Turn on cohorting in the course. """
        set_course_cohorted(self.course.id, True)

    def _create_verified_cohort(self, name=DEFAULT_VERIFIED_COHORT_NAME):
        """ Create a verified cohort. """
        add_cohort(self.course.id, name, CourseCohort.MANUAL)

    def _create_named_random_cohort(self, name):
        """ Create a random cohort with the supplied name. """
        return add_cohort(self.course.id, name, CourseCohort.RANDOM)

    def _enable_verified_track_cohorting(self, cohort_name=None):
        """ Enable verified track cohorting for the default course. """
        if cohort_name:
            config = VerifiedTrackCohortedCourse.objects.create(
                course_key=self.course.id, enabled=True, verified_cohort_name=cohort_name
            )
        else:
            config = VerifiedTrackCohortedCourse.objects.create(course_key=self.course.id, enabled=True)
        config.save()

    def _enroll_in_course(self):
        """ Enroll self.user in self.course. """
        self.enrollment = CourseEnrollmentFactory(course_id=self.course.id, user=self.user)

    def _upgrade_enrollment(self, mode=CourseMode.VERIFIED):
        """ Upgrade the default enrollment to verified. """
        self.enrollment.update_enrollment(mode=mode)

    def _verify_no_automatic_cohorting(self):
        """ Check that upgrading self.user to verified does not move them into a cohort. """
        self._enroll_in_course()
        self.assertIsNone(get_cohort(self.user, self.course.id, assign=False))
        self._upgrade_enrollment()
        self.assertIsNone(get_cohort(self.user, self.course.id, assign=False))
        self.assertEqual(0, self.mocked_celery_task.call_count)

    def _unenroll(self):
        """ Unenroll self.user from self.course. """
        self.enrollment.unenroll(self.user, self.course.id)

    def _reenroll(self):
        """ Re-enroll the learner into mode AUDIT. """
        self.enrollment.activate()
        self.enrollment.change_mode(CourseMode.AUDIT)

    @mock.patch('openedx.core.djangoapps.verified_track_content.models.log.error')
    def test_automatic_cohorting_disabled(self, error_logger):
        """
        If the VerifiedTrackCohortedCourse feature is disabled for a course, enrollment mode changes do not move
        learners into a cohort.
        """
        # Enable cohorting and create a verified cohort.
        self._enable_cohorting()
        self._create_verified_cohort()
        # But do not enable the verified track cohorting feature.
        self.assertFalse(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
        self._verify_no_automatic_cohorting()
        # No logging occurs if feature is disabled for course.
        self.assertFalse(error_logger.called)

    @mock.patch('openedx.core.djangoapps.verified_track_content.models.log.error')
    def test_cohorting_enabled_course_not_cohorted(self, error_logger):
        """
        If the VerifiedTrackCohortedCourse feature is enabled for a course, but the course is not cohorted,
        an error is logged and enrollment mode changes do not move learners into a cohort.
        """
        # Enable verified track cohorting feature, but course has not been marked as cohorting.
        self._enable_verified_track_cohorting()
        self.assertTrue(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
        self._verify_no_automatic_cohorting()
        self.assertTrue(error_logger.called)
        self.assertIn("course is not cohorted", error_logger.call_args[0][0])

    @mock.patch('openedx.core.djangoapps.verified_track_content.models.log.error')
    def test_cohorting_enabled_missing_verified_cohort(self, error_logger):
        """
        If the VerifiedTrackCohortedCourse feature is enabled for a course and the course is cohorted,
        but the course does not have a verified cohort, an error is logged and enrollment mode changes do not
        move learners into a cohort.
#.........这里部分代码省略.........
开发者ID:edx,项目名称:edx-platform,代码行数:103,代码来源:test_models.py

示例2: TestMoveToVerified

# 需要导入模块: from student.tests.factories import CourseEnrollmentFactory [as 别名]
# 或者: from student.tests.factories.CourseEnrollmentFactory import update_enrollment [as 别名]
class TestMoveToVerified(SharedModuleStoreTestCase):
    """ Tests for the post-save listener. """

    @classmethod
    def setUpClass(cls):
        super(TestMoveToVerified, cls).setUpClass()
        cls.course = CourseFactory.create()

    def setUp(self):
        self.user = UserFactory()
        # Spy on number of calls to celery task.
        celery_task_patcher = patch.object(
            sync_cohort_with_mode, 'apply_async',
            mock.Mock(wraps=sync_cohort_with_mode.apply_async)
        )
        self.mocked_celery_task = celery_task_patcher.start()
        self.addCleanup(celery_task_patcher.stop)

    def _enable_cohorting(self):
        set_course_cohort_settings(self.course.id, is_cohorted=True)

    def _create_verified_cohort(self, name=DEFAULT_VERIFIED_COHORT_NAME):
        add_cohort(self.course.id, name, CourseCohort.MANUAL)

    def _enable_verified_track_cohorting(self, cohort_name=None):
        """ Enable verified track cohorting for the default course. """
        if cohort_name:
            config = VerifiedTrackCohortedCourse.objects.create(
                course_key=self.course.id, enabled=True, verified_cohort_name=cohort_name
            )
        else:
            config = VerifiedTrackCohortedCourse.objects.create(course_key=self.course.id, enabled=True)
        config.save()

    def _enroll_in_course(self):
        self.enrollment = CourseEnrollmentFactory(course_id=self.course.id, user=self.user)

    def _upgrade_to_verified(self):
        """ Upgrade the default enrollment to verified. """
        self.enrollment.update_enrollment(mode=CourseMode.VERIFIED)

    def _verify_no_automatic_cohorting(self):
        self._enroll_in_course()
        self.assertIsNone(get_cohort(self.user, self.course.id, assign=False))
        self._upgrade_to_verified()
        self.assertIsNone(get_cohort(self.user, self.course.id, assign=False))
        self.assertEqual(0, self.mocked_celery_task.call_count)

    def _unenroll(self):
        self.enrollment.unenroll(self.user, self.course.id)

    def _reenroll(self):
        self.enrollment.activate()
        self.enrollment.change_mode(CourseMode.AUDIT)

    @mock.patch('verified_track_content.models.log.error')
    def test_automatic_cohorting_disabled(self, error_logger):
        """
        If the VerifiedTrackCohortedCourse feature is disabled for a course, enrollment mode changes do not move
        learners into a cohort.
        """
        # Enable cohorting and create a verified cohort.
        self._enable_cohorting()
        self._create_verified_cohort()
        # But do not enable the verified track cohorting feature.
        self.assertFalse(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
        self._verify_no_automatic_cohorting()
        # No logging occurs if feature is disabled for course.
        self.assertFalse(error_logger.called)

    @mock.patch('verified_track_content.models.log.error')
    def test_cohorting_enabled_course_not_cohorted(self, error_logger):
        """
        If the VerifiedTrackCohortedCourse feature is enabled for a course, but the course is not cohorted,
        an error is logged and enrollment mode changes do not move learners into a cohort.
        """
        # Enable verified track cohorting feature, but course has not been marked as cohorting.
        self._enable_verified_track_cohorting()
        self.assertTrue(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
        self._verify_no_automatic_cohorting()
        self.assertTrue(error_logger.called)
        self.assertIn("course is not cohorted", error_logger.call_args[0][0])

    @mock.patch('verified_track_content.models.log.error')
    def test_cohorting_enabled_missing_verified_cohort(self, error_logger):
        """
        If the VerifiedTrackCohortedCourse feature is enabled for a course and the course is cohorted,
        but the course does not have a verified cohort, an error is logged and enrollment mode changes do not
        move learners into a cohort.
        """
        # Enable cohorting, but do not create the verified cohort.
        self._enable_cohorting()
        # Enable verified track cohorting feature
        self._enable_verified_track_cohorting()
        self.assertTrue(VerifiedTrackCohortedCourse.is_verified_track_cohort_enabled(self.course.id))
        self._verify_no_automatic_cohorting()
        self.assertTrue(error_logger.called)
        error_message = "cohort named '%s' does not exist"
        self.assertIn(error_message, error_logger.call_args[0][0])

#.........这里部分代码省略.........
开发者ID:mf1389004071,项目名称:edx-platform,代码行数:103,代码来源:test_models.py


注:本文中的student.tests.factories.CourseEnrollmentFactory.update_enrollment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。