示例#1
0
    def test_caching_global(self):
        global_config = ContentTypeGatingConfig(enabled=True,
                                                enabled_as_of=datetime(
                                                    2018, 1, 1))
        global_config.save()

        RequestCache.clear_all_namespaces()

        # Check that the global value is not retrieved from cache after save
        with self.assertNumQueries(1):
            assert ContentTypeGatingConfig.current().enabled

        RequestCache.clear_all_namespaces()

        # Check that the global value can be retrieved from cache after read
        with self.assertNumQueries(0):
            assert ContentTypeGatingConfig.current().enabled

        global_config.enabled = False
        global_config.save()

        RequestCache.clear_all_namespaces()

        # Check that the global value in cache was deleted on save
        with self.assertNumQueries(1):
            assert not ContentTypeGatingConfig.current().enabled
示例#2
0
    def test_caching_course(self):
        course = CourseOverviewFactory.create(org='test-org')
        site_cfg = SiteConfigurationFactory.create(
            values={'course_org_filter': course.org})
        course_config = ContentTypeGatingConfig(course=course,
                                                enabled=True,
                                                enabled_as_of=datetime(
                                                    2018, 1, 1))
        course_config.save()

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

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

        course_config.enabled = False
        course_config.save()

        # Check that the org value in cache was deleted on save
        with self.assertNumQueries(2):
            self.assertFalse(
                ContentTypeGatingConfig.current(course_key=course.id).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(course_key=course.id).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(course_key=course.id).enabled)

        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 updated in cache by changing the site value
        with self.assertNumQueries(0):
            self.assertFalse(
                ContentTypeGatingConfig.current(course_key=course.id).enabled)
示例#3
0
    def test_caching_course(self):
        course = CourseOverviewFactory.create(org='test-org')
        site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': course.org})
        course_config = ContentTypeGatingConfig(course=course, enabled=True, enabled_as_of=datetime(2018, 1, 1))
        course_config.save()

        RequestCache.clear_all_namespaces()

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

        RequestCache.clear_all_namespaces()

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

        course_config.enabled = False
        course_config.save()

        RequestCache.clear_all_namespaces()

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

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

        RequestCache.clear_all_namespaces()

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

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

        RequestCache.clear_all_namespaces()

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

        org_config = ContentTypeGatingConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1))
        org_config.save()

        RequestCache.clear_all_namespaces()

        # Check that the org value is not updated in cache by changing the site value
        with self.assertNumQueries(0):
            self.assertFalse(ContentTypeGatingConfig.current(course_key=course.id).enabled)
示例#4
0
    def test_caching_global(self):
        global_config = ContentTypeGatingConfig(enabled=True, enabled_as_of=date(2018, 1, 1))
        global_config.save()

        # Check that the global value is not retrieved from cache after save
        with self.assertNumQueries(1):
            self.assertTrue(ContentTypeGatingConfig.current().enabled)

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

        global_config.enabled = False
        global_config.save()

        # Check that the global value in cache was deleted on save
        with self.assertNumQueries(1):
            self.assertFalse(ContentTypeGatingConfig.current().enabled)
示例#5
0
    def test_caching_global(self):
        global_config = ContentTypeGatingConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1))
        global_config.save()

        # Check that the global value is not retrieved from cache after save
        with self.assertNumQueries(1):
            self.assertTrue(ContentTypeGatingConfig.current().enabled)

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

        global_config.enabled = False
        global_config.save()

        # Check that the global value in cache was deleted on save
        with self.assertNumQueries(1):
            self.assertFalse(ContentTypeGatingConfig.current().enabled)
示例#6
0
    def test_caching_org(self):
        course = CourseOverviewFactory.create(org='test-org')
        site_cfg = SiteConfigurationFactory.create(
            site_values={'course_org_filter': course.org})
        org_config = ContentTypeGatingConfig(org=course.org,
                                             enabled=True,
                                             enabled_as_of=datetime(
                                                 2018, 1, 1))
        org_config.save()

        RequestCache.clear_all_namespaces()

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

        RequestCache.clear_all_namespaces()

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

        org_config.enabled = False
        org_config.save()

        RequestCache.clear_all_namespaces()

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

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

        RequestCache.clear_all_namespaces()

        # Check that the org value is not updated in cache by changing the global value
        with self.assertNumQueries(0):
            assert not 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()

        RequestCache.clear_all_namespaces()

        # Check that the org value is not updated in cache by changing the site value
        with self.assertNumQueries(0):
            assert not ContentTypeGatingConfig.current(org=course.org).enabled
示例#7
0
    def test_caching_site(self):
        site_cfg = SiteConfigurationFactory()
        site_config = ContentTypeGatingConfig(site=site_cfg.site, enabled=True, enabled_as_of=date(2018, 1, 1))
        site_config.save()

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

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

        site_config.enabled = False
        site_config.save()

        # Check that the site value in cache was deleted on save
        with self.assertNumQueries(1):
            self.assertFalse(ContentTypeGatingConfig.current(site=site_cfg.site).enabled)

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

        # Check that the site value is not updated in cache by changing the global value
        with self.assertNumQueries(0):
            self.assertFalse(ContentTypeGatingConfig.current(site=site_cfg.site).enabled)
示例#8
0
    def test_caching_site(self):
        site_cfg = SiteConfigurationFactory()
        site_config = ContentTypeGatingConfig(site=site_cfg.site, enabled=True, enabled_as_of=datetime(2018, 1, 1))
        site_config.save()

        RequestCache.clear_all_namespaces()

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

        RequestCache.clear_all_namespaces()

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

        site_config.enabled = False
        site_config.save()

        RequestCache.clear_all_namespaces()

        # Check that the site value in cache was deleted on save
        with self.assertNumQueries(1):
            self.assertFalse(ContentTypeGatingConfig.current(site=site_cfg.site).enabled)

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

        RequestCache.clear_all_namespaces()

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