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


Python ContentTypeGatingConfig.all_current_course_configs方法代码示例

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


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

示例1: test_all_current_course_configs

# 需要导入模块: from openedx.features.content_type_gating.models import ContentTypeGatingConfig [as 别名]
# 或者: from openedx.features.content_type_gating.models.ContentTypeGatingConfig import all_current_course_configs [as 别名]
    def test_all_current_course_configs(self):
        # Set up test objects
        for global_setting in (True, False, None):
            ContentTypeGatingConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1))
            for site_setting in (True, False, None):
                test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': []})
                ContentTypeGatingConfig.objects.create(site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1))

                for org_setting in (True, False, None):
                    test_org = "{}-{}".format(test_site_cfg.id, org_setting)
                    test_site_cfg.values['course_org_filter'].append(test_org)
                    test_site_cfg.save()

                    ContentTypeGatingConfig.objects.create(org=test_org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1))

                    for course_setting in (True, False, None):
                        test_course = CourseOverviewFactory.create(
                            org=test_org,
                            id=CourseLocator(test_org, 'test_course', 'run-{}'.format(course_setting))
                        )
                        ContentTypeGatingConfig.objects.create(course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1))

            with self.assertNumQueries(4):
                all_configs = ContentTypeGatingConfig.all_current_course_configs()

        # Deliberatly using the last all_configs that was checked after the 3rd pass through the global_settings loop
        # We should be creating 3^4 courses (3 global values * 3 site values * 3 org values * 3 course values)
        # Plus 1 for the edX/toy/2012_Fall course
        self.assertEqual(len(all_configs), 3**4 + 1)

        # Point-test some of the final configurations
        self.assertEqual(
            all_configs[CourseLocator('7-True', 'test_course', 'run-None')],
            {
                'enabled': (True, Provenance.org),
                'enabled_as_of': (datetime(2018, 1, 1, 5, tzinfo=pytz.UTC), Provenance.run),
                'studio_override_enabled': (None, Provenance.default),
            }
        )
        self.assertEqual(
            all_configs[CourseLocator('7-True', 'test_course', 'run-False')],
            {
                'enabled': (False, Provenance.run),
                'enabled_as_of': (datetime(2018, 1, 1, 5, tzinfo=pytz.UTC), Provenance.run),
                'studio_override_enabled': (None, Provenance.default),
            }
        )
        self.assertEqual(
            all_configs[CourseLocator('7-None', 'test_course', 'run-None')],
            {
                'enabled': (True, Provenance.site),
                'enabled_as_of': (datetime(2018, 1, 1, 5, tzinfo=pytz.UTC), Provenance.run),
                'studio_override_enabled': (None, Provenance.default),
            }
        )
开发者ID:edx,项目名称:edx-platform,代码行数:57,代码来源:test_models.py


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