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


Python factories.SiteConfigurationFactory类代码示例

本文整理汇总了Python中openedx.core.djangoapps.site_configuration.tests.factories.SiteConfigurationFactory的典型用法代码示例。如果您正苦于以下问题:Python SiteConfigurationFactory类的具体用法?Python SiteConfigurationFactory怎么用?Python SiteConfigurationFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_site_config

    def test_site_config(self, org_list, exclude_orgs, expected_message_count, mock_schedule_send, mock_ace):
        filtered_org = 'filtered_org'
        unfiltered_org = 'unfiltered_org'
        site1 = SiteFactory.create(domain='foo1.bar', name='foo1.bar')
        limited_config = SiteConfigurationFactory.create(values={'course_org_filter': [filtered_org]}, site=site1)
        site2 = SiteFactory.create(domain='foo2.bar', name='foo2.bar')
        unlimited_config = SiteConfigurationFactory.create(values={'course_org_filter': []}, site=site2)

        for config in (limited_config, unlimited_config):
            ScheduleConfigFactory.create(site=config.site)

        ScheduleFactory.create(
            start=datetime.datetime(2017, 8, 2, 17, 44, 30, tzinfo=pytz.UTC),
            enrollment__course__org=filtered_org,
        )
        for _ in range(2):
            ScheduleFactory.create(
                start=datetime.datetime(2017, 8, 2, 17, 44, 30, tzinfo=pytz.UTC),
                enrollment__course__org=unfiltered_org,
            )

        test_time_str = serialize(datetime.datetime(2017, 8, 2, 17, tzinfo=pytz.UTC))
        with self.assertNumQueries(2):
            tasks.recurring_nudge_schedule_hour(
                limited_config.site.id, 3, test_time_str, org_list=org_list, exclude_orgs=exclude_orgs,
            )

        self.assertEqual(mock_schedule_send.apply_async.call_count, expected_message_count)
        self.assertFalse(mock_ace.send.called)
开发者ID:francishan,项目名称:edx-platform,代码行数:29,代码来源:test_send_recurring_nudge.py

示例2: test_site_config

    def test_site_config(self, this_org_list, other_org_list, expected_message_count, mock_ace):
        filtered_org = 'filtered_org'
        unfiltered_org = 'unfiltered_org'
        this_config = SiteConfigurationFactory.create(values={'course_org_filter': this_org_list})
        other_config = SiteConfigurationFactory.create(values={'course_org_filter': other_org_list})

        for config in (this_config, other_config):
            ScheduleConfigFactory.create(site=config.site)

        user1 = UserFactory.create(id=self.task.num_bins)
        user2 = UserFactory.create(id=self.task.num_bins * 2)
        current_day, offset, target_day, upgrade_deadline = self._get_dates()

        self._schedule_factory(
            enrollment__course__org=filtered_org,
            enrollment__user=user1,
        )
        self._schedule_factory(
            enrollment__course__org=unfiltered_org,
            enrollment__user=user1,
        )
        self._schedule_factory(
            enrollment__course__org=unfiltered_org,
            enrollment__user=user2,
        )

        with patch.object(self.task, 'async_send_task') as mock_schedule_send:
            self.task().apply(kwargs=dict(
                site_id=this_config.site.id, target_day_str=serialize(target_day), day_offset=offset, bin_num=0
            ))

        self.assertEqual(mock_schedule_send.apply_async.call_count, expected_message_count)
        self.assertFalse(mock_ace.send.called)
开发者ID:mitocw,项目名称:edx-platform,代码行数:33,代码来源:send_email_base.py

示例3: setUp

    def setUp(self):
        super(SiteMixin, self).setUp()

        self.site = SiteFactory.create()
        self.site_configuration = SiteConfigurationFactory.create(
            site=self.site,
            values={
                "SITE_NAME": self.site.domain,
                "course_email_from_addr": "[email protected]",
                "course_email_template_name": "fake_email_template",
                "course_org_filter": "fakeX"
            }
        )

        self.site_other = SiteFactory.create(
            domain='testserver.fakeother',
            name='testserver.fakeother'
        )
        self.site_configuration_other = SiteConfigurationFactory.create(
            site=self.site_other,
            values={
                "SITE_NAME": self.site_other.domain,
                "SESSION_COOKIE_DOMAIN": self.site_other.domain,
                "course_org_filter": "fakeOtherX",
                "ENABLE_MKTG_SITE": True,
                "SHOW_ECOMMERCE_REPORTS": True,
                "MKTG_URLS": {
                    "ROOT": "https://marketing.fakeother",
                    "ABOUT": "/fake-about"
                }
            }
        )

        # Initialize client with default site domain
        self.use_site(self.site)
开发者ID:edx,项目名称:edx-platform,代码行数:35,代码来源:mixins.py

示例4: test_no_entry_is_saved_for_errors

    def test_no_entry_is_saved_for_errors(self):
        """
        Test that and entry is not added to SiteConfigurationHistory if there is an error while
        saving SiteConfiguration.
        """
        # add SiteConfiguration to database
        site_configuration = SiteConfigurationFactory.create(
            site=self.site,
        )

        # Verify an entry to SiteConfigurationHistory was added.
        site_configuration_history = SiteConfigurationHistory.objects.filter(
            site=site_configuration.site,
        ).all()

        # Make sure entry is saved if there is no error
        self.assertEqual(len(site_configuration_history), 1)

        with transaction.atomic():
            with self.assertRaises(IntegrityError):
                # try to add a duplicate entry
                site_configuration = SiteConfigurationFactory.create(
                    site=self.site,
                )
        site_configuration_history = SiteConfigurationHistory.objects.filter(
            site=site_configuration.site,
        ).all()

        # Make sure no entry is saved if there an error
        self.assertEqual(len(site_configuration_history), 1)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:30,代码来源:test_models.py

示例5: test_get_site_for_org

    def test_get_site_for_org(self):
        """
        Test that get_value_for_org returns correct value for any given key.
        """
        # add SiteConfiguration to database
        config1 = SiteConfigurationFactory.create(
            site=self.site,
            values=self.test_config1,
        )
        config2 = SiteConfigurationFactory.create(
            site=self.site2,
            values=self.test_config2,
        )

        # Make sure entry is saved and retrieved correctly
        self.assertEqual(
            SiteConfiguration.get_configuration_for_org(self.test_config1['course_org_filter']),
            config1,
        )
        self.assertEqual(
            SiteConfiguration.get_configuration_for_org(self.test_config2['course_org_filter']),
            config2,
        )
        self.assertEqual(
            SiteConfiguration.get_configuration_for_org('something else'),
            None,
        )
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:27,代码来源:test_models.py

示例6: test_get_course_org_filter_exclude__in

 def test_get_course_org_filter_exclude__in(self, course_org_filter, expected_org_list):
     SiteConfigurationFactory.create(
         values={'course_org_filter': course_org_filter},
     )
     mock_query = Mock()
     result = self.resolver.filter_by_org(mock_query)
     mock_query.exclude.assert_called_once_with(enrollment__course__org__in=expected_org_list)
     self.assertEqual(result, mock_query.exclude.return_value)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:8,代码来源:test_resolvers.py

示例7: test_get_all_orgs_returns_only_enabled

    def test_get_all_orgs_returns_only_enabled(self):
        """
        Test that get_all_orgs returns only those orgs whose configurations are enabled.
        """
        expected_orgs = [self.test_config2["course_org_filter"]]
        # add SiteConfiguration to database
        SiteConfigurationFactory.create(site=self.site, values=self.test_config1, enabled=False)
        SiteConfigurationFactory.create(site=self.site2, values=self.test_config2)

        # Test that the default value is returned if the value for the given key is not found in the configuration
        self.assertListEqual(list(SiteConfiguration.get_all_orgs()), expected_orgs)
开发者ID:hastexo,项目名称:edx-platform,代码行数:11,代码来源:test_models.py

示例8: test_get_all_orgs

    def test_get_all_orgs(self):
        """
        Test that get_all_orgs returns all orgs from site configuration.
        """
        expected_orgs = [self.test_config1["course_org_filter"], self.test_config2["course_org_filter"]]
        # add SiteConfiguration to database
        SiteConfigurationFactory.create(site=self.site, values=self.test_config1)
        SiteConfigurationFactory.create(site=self.site2, values=self.test_config2)

        # Test that the default value is returned if the value for the given key is not found in the configuration
        self.assertListEqual(list(SiteConfiguration.get_all_orgs()), expected_orgs)
开发者ID:hastexo,项目名称:edx-platform,代码行数:11,代码来源:test_models.py

示例9: TestBinnedSchedulesBaseResolver

class TestBinnedSchedulesBaseResolver(CacheIsolationTestCase):
    def setUp(self):
        super(TestBinnedSchedulesBaseResolver, self).setUp()

        self.site = SiteFactory.create()
        self.site_config = SiteConfigurationFactory(site=self.site)
        self.schedule_config = ScheduleConfigFactory.create(site=self.site)
        self.resolver = BinnedSchedulesBaseResolver(
            async_send_task=Mock(name='async_send_task'),
            site=self.site,
            target_datetime=datetime.datetime.now(),
            day_offset=3,
            bin_num=2,
        )

    @ddt.data(
        'course1'
    )
    def test_get_course_org_filter_equal(self, course_org_filter):
        self.site_config.values['course_org_filter'] = course_org_filter
        self.site_config.save()
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        self.assertEqual(result, mock_query.filter.return_value)
        mock_query.filter.assert_called_once_with(enrollment__course__org=course_org_filter)

    @ddt.unpack
    @ddt.data(
        (['course1', 'course2'], ['course1', 'course2'])
    )
    def test_get_course_org_filter_include__in(self, course_org_filter, expected_org_list):
        self.site_config.values['course_org_filter'] = course_org_filter
        self.site_config.save()
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        self.assertEqual(result, mock_query.filter.return_value)
        mock_query.filter.assert_called_once_with(enrollment__course__org__in=expected_org_list)

    @ddt.unpack
    @ddt.data(
        (None, set([])),
        ('course1', set([u'course1'])),
        (['course1', 'course2'], set([u'course1', u'course2']))
    )
    def test_get_course_org_filter_exclude__in(self, course_org_filter, expected_org_list):
        SiteConfigurationFactory.create(
            values={'course_org_filter': course_org_filter},
        )
        mock_query = Mock()
        result = self.resolver.filter_by_org(mock_query)
        mock_query.exclude.assert_called_once_with(enrollment__course__org__in=expected_org_list)
        self.assertEqual(result, mock_query.exclude.return_value)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:52,代码来源:test_resolvers.py

示例10: test_config_overrides

    def test_config_overrides(self, global_setting, site_setting, org_setting, course_setting, reverse_order):
        """
        Test that the stacked configuration overrides happen in the correct order and priority.

        This is tested by exhaustively setting each combination of contexts, and validating that only
        the lowest level context that is set to not-None is applied.
        """
        # Add a bunch of configuration outside the contexts that are being tested, to make sure
        # there are no leaks of configuration across contexts
        non_test_course_enabled = CourseOverviewFactory.create(org='non-test-org-enabled')
        non_test_course_disabled = CourseOverviewFactory.create(org='non-test-org-disabled')
        non_test_site_cfg_enabled = SiteConfigurationFactory.create(
            values={'course_org_filter': non_test_course_enabled.org}
        )
        non_test_site_cfg_disabled = SiteConfigurationFactory.create(
            values={'course_org_filter': non_test_course_disabled.org}
        )

        CourseDurationLimitConfig.objects.create(course=non_test_course_enabled, enabled=True)
        CourseDurationLimitConfig.objects.create(course=non_test_course_disabled, enabled=False)
        CourseDurationLimitConfig.objects.create(org=non_test_course_enabled.org, enabled=True)
        CourseDurationLimitConfig.objects.create(org=non_test_course_disabled.org, enabled=False)
        CourseDurationLimitConfig.objects.create(site=non_test_site_cfg_enabled.site, enabled=True)
        CourseDurationLimitConfig.objects.create(site=non_test_site_cfg_disabled.site, enabled=False)

        # Set up test objects
        test_course = CourseOverviewFactory.create(org='test-org')
        test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': test_course.org})

        if reverse_order:
            CourseDurationLimitConfig.objects.create(site=test_site_cfg.site, enabled=site_setting)
            CourseDurationLimitConfig.objects.create(org=test_course.org, enabled=org_setting)
            CourseDurationLimitConfig.objects.create(course=test_course, enabled=course_setting)
            CourseDurationLimitConfig.objects.create(enabled=global_setting)
        else:
            CourseDurationLimitConfig.objects.create(enabled=global_setting)
            CourseDurationLimitConfig.objects.create(course=test_course, enabled=course_setting)
            CourseDurationLimitConfig.objects.create(org=test_course.org, enabled=org_setting)
            CourseDurationLimitConfig.objects.create(site=test_site_cfg.site, enabled=site_setting)

        expected_global_setting = self._resolve_settings([global_setting])
        expected_site_setting = self._resolve_settings([global_setting, site_setting])
        expected_org_setting = self._resolve_settings([global_setting, site_setting, org_setting])
        expected_course_setting = self._resolve_settings([global_setting, site_setting, org_setting, course_setting])

        self.assertEqual(expected_global_setting, CourseDurationLimitConfig.current().enabled)
        self.assertEqual(expected_site_setting, CourseDurationLimitConfig.current(site=test_site_cfg.site).enabled)
        self.assertEqual(expected_org_setting, CourseDurationLimitConfig.current(org=test_course.org).enabled)
        self.assertEqual(expected_course_setting, CourseDurationLimitConfig.current(course_key=test_course.id).enabled)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:49,代码来源:test_models.py

示例11: test_caching_org

    def test_caching_org(self):
        course = CourseOverviewFactory.create(org='test-org')
        site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': course.org})
        org_config = ContentTypeGatingConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1))
        org_config.save()

        # Check that the org value is not retrieved from cache after save
        with self.assertNumQueries(2):
            self.assertTrue(ContentTypeGatingConfig.current(org=course.org).enabled)

        # Check that the org value can be retrieved from cache after read
        with self.assertNumQueries(0):
            self.assertTrue(ContentTypeGatingConfig.current(org=course.org).enabled)

        org_config.enabled = False
        org_config.save()

        # Check that the org value in cache was deleted on save
        with self.assertNumQueries(2):
            self.assertFalse(ContentTypeGatingConfig.current(org=course.org).enabled)

        global_config = ContentTypeGatingConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1))
        global_config.save()

        # Check that the org value is not updated in cache by changing the global value
        with self.assertNumQueries(0):
            self.assertFalse(ContentTypeGatingConfig.current(org=course.org).enabled)

        site_config = ContentTypeGatingConfig(site=site_cfg.site, enabled=True, enabled_as_of=datetime(2018, 1, 1))
        site_config.save()

        # Check that the org value is not updated in cache by changing the site value
        with self.assertNumQueries(0):
            self.assertFalse(ContentTypeGatingConfig.current(org=course.org).enabled)
开发者ID:mitocw,项目名称:edx-platform,代码行数:34,代码来源:test_models.py

示例12: test_site

    def test_site(self, mock_grade_interesting, mock_cert_change):
        site_config = SiteConfigurationFactory.create(
            values={'course_org_filter': ['testX']},
        )

        call_command(Command(), '--site', site_config.site.domain, '--start-date', '2017-01-01')
        self.assertEqual(mock_grade_interesting.call_count, 1)
        self.assertEqual(mock_cert_change.call_count, 1)
开发者ID:mitocw,项目名称:edx-platform,代码行数:8,代码来源:test_notify_credentials.py

示例13: test_comment_created_signal_sends_message

    def test_comment_created_signal_sends_message(self, mock_send_message, mock_get_current_site):
        site_config = SiteConfigurationFactory.create(site=self.site)
        site_config.values[ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY] = True
        site_config.save()
        mock_get_current_site.return_value = self.site
        signals.comment_created.send(sender=self.sender, user=self.user, post=self.post)

        mock_send_message.assert_called_once_with(self.post, mock_get_current_site.return_value)
开发者ID:luisvasq,项目名称:edx-platform,代码行数:8,代码来源:test_signals.py

示例14: test_site_config_override

 def test_site_config_override(self):
     site_config = SiteConfigurationFactory.create(
         values=dict(
             GOOGLE_ANALYTICS_ACCOUNT='UA-654321-1'
         )
     )
     pixel = GoogleAnalyticsTrackingPixel(site=site_config.site)
     self.assert_query_string_parameters_equal(pixel.generate_image_url(), tid='UA-654321-1')
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:8,代码来源:test_tracking.py

示例15: setUp

    def setUp(self):
        ScheduleFactory.create(start=datetime.datetime(2017, 8, 1, 15, 44, 30, tzinfo=pytz.UTC))
        ScheduleFactory.create(start=datetime.datetime(2017, 8, 1, 17, 34, 30, tzinfo=pytz.UTC))
        ScheduleFactory.create(start=datetime.datetime(2017, 8, 2, 15, 34, 30, tzinfo=pytz.UTC))

        site = SiteFactory.create()
        self.site_config = SiteConfigurationFactory.create(site=site)
        ScheduleConfigFactory.create(site=self.site_config.site)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:8,代码来源:test_send_recurring_nudge.py


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