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


Python RequestCache.clear_all_namespaces方法代码示例

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


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

示例1: test_setting_override

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
 def test_setting_override(self, is_enabled, override_choice, expected_result):
     RequestCache.clear_all_namespaces()
     self.set_waffle_course_override(override_choice, is_enabled)
     override_value = WaffleFlagCourseOverrideModel.override_value(
         self.WAFFLE_TEST_NAME, self.TEST_COURSE_KEY
     )
     self.assertEqual(override_value, expected_result)
开发者ID:edx,项目名称:edx-platform,代码行数:9,代码来源:test_models.py

示例2: _clear_request_cache

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
def _clear_request_cache(**kwargs):
    """
    Once a celery task completes, clear the request cache to
    prevent memory leaks.
    """
    if getattr(settings, 'CLEAR_REQUEST_CACHE_ON_TASK_COMPLETION', True):
        RequestCache.clear_all_namespaces()
开发者ID:mitocw,项目名称:edx-platform,代码行数:9,代码来源:signals.py

示例3: test_get_template_path

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
    def test_get_template_path(self):
        """
        Tests to make sure the get_template_path function works as expected.
        """
        # if the current site has associated SiteTheme then get_template_path should return the argument as is.
        with patch(
            "openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
            Mock(return_value=True),
        ):
            with patch(
                "openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
                Mock(return_value=True),
            ):
                with patch("microsite_configuration.microsite.TEMPLATES_BACKEND") as mock_microsite_backend:
                    mock_microsite_backend.get_template = Mock(return_value="/microsite/about.html")
                    self.assertEqual(theming_helpers.get_template_path("about.html"), "about.html")

        RequestCache.clear_all_namespaces()

        # if the current site does not have associated SiteTheme then get_template_path should return microsite override
        with patch(
            "openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
            Mock(return_value=False),
        ):
            with patch(
                "openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
                Mock(return_value=True),
            ):
                with patch("microsite_configuration.microsite.TEMPLATES_BACKEND") as mock_microsite_backend:
                    mock_microsite_backend.get_template_path = Mock(return_value="/microsite/about.html")
                    self.assertEqual(theming_helpers.get_template_path("about.html"), "/microsite/about.html")
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:33,代码来源:test_helpers.py

示例4: instrument_course_progress_render

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
    def instrument_course_progress_render(
            self, course_width, enable_ccx, view_as_ccx,
            sql_queries, mongo_reads,
    ):
        """
        Renders the progress page, instrumenting Mongo reads and SQL queries.
        """
        course_key = self.setup_course(course_width, enable_ccx, view_as_ccx)

        # Switch to published-only mode to simulate the LMS
        with self.settings(MODULESTORE_BRANCH='published-only'):
            # Clear all caches before measuring
            for cache in settings.CACHES:
                caches[cache].clear()

            # Refill the metadata inheritance cache
            get_course_in_cache(course_key)

            # We clear the request cache to simulate a new request in the LMS.
            RequestCache.clear_all_namespaces()

            # Reset the list of provider classes, so that our django settings changes
            # can actually take affect.
            OverrideFieldData.provider_classes = None

            with self.assertNumQueries(sql_queries, using='default', table_blacklist=QUERY_COUNT_TABLE_BLACKLIST):
                with self.assertNumQueries(0, using='student_module_history'):
                    with self.assertMongoCallCount(mongo_reads):
                        with self.assertXBlockInstantiations(1):
                            self.grade_course(course_key)
开发者ID:mitocw,项目名称:edx-platform,代码行数:32,代码来源:test_field_override_performance.py

示例5: test_setting_override_multiple_times

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
 def test_setting_override_multiple_times(self):
     RequestCache.clear_all_namespaces()
     self.set_waffle_course_override(self.OVERRIDE_CHOICES.on)
     self.set_waffle_course_override(self.OVERRIDE_CHOICES.off)
     override_value = WaffleFlagCourseOverrideModel.override_value(
         self.WAFFLE_TEST_NAME, self.TEST_COURSE_KEY
     )
     self.assertEqual(override_value, self.OVERRIDE_CHOICES.off)
开发者ID:edx,项目名称:edx-platform,代码行数:10,代码来源:test_models.py

示例6: lti_consumer_fields_editing_flag

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
def lti_consumer_fields_editing_flag(course_id, enabled_for_course=False):
    """
    Yields CourseEditLTIFieldsEnabledFlag record for unit tests

    Arguments:
        course_id (CourseLocator): course locator to control this feature for.
        enabled_for_course (bool): whether feature is enabled for 'course_id'
    """
    RequestCache.clear_all_namespaces()
    CourseEditLTIFieldsEnabledFlag.objects.create(course_id=course_id, enabled=enabled_for_course)
    yield
开发者ID:albluqmun,项目名称:edx-platform,代码行数:13,代码来源:test_models.py

示例7: assert_access_to_gated_content

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
    def assert_access_to_gated_content(self, user):
        """
        Verifies access to gated content for the given user is as expected.
        """
        # clear the request cache to flush any cached access results
        RequestCache.clear_all_namespaces()

        # access to gating content (seq1) remains constant
        self.assertTrue(bool(has_access(user, 'load', self.seq1, self.course.id)))

        # access to gated content (seq2) remains constant, access is prevented in SeqModule loading
        self.assertTrue(bool(has_access(user, 'load', self.seq2, self.course.id)))
开发者ID:jolyonb,项目名称:edx-platform,代码行数:14,代码来源:test_integration.py

示例8: test_caching_site

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
    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)
开发者ID:edx,项目名称:edx-platform,代码行数:36,代码来源:test_models.py

示例9: test_too_many_courses

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
    def test_too_many_courses(self):
        """
        Test that search results are limited to 100 courses, and that they don't
        blow up the database.
        """

        ContentTypeGatingConfig.objects.create(
            enabled=True,
            enabled_as_of=datetime(2018, 1, 1),
        )

        CourseDurationLimitConfig.objects.create(
            enabled=True,
            enabled_as_of=datetime(2018, 1, 1),
        )

        course_ids = []

        # Create 300 courses across 30 organizations
        for org_num in range(10):
            org_id = 'org{}'.format(org_num)
            for course_num in range(30):
                course_name = 'course{}.{}'.format(org_num, course_num)
                course_run_name = 'run{}.{}'.format(org_num, course_num)
                course = CourseFactory.create(org=org_id, number=course_name, run=course_run_name, emit_signals=True)
                CourseModeFactory.create(course_id=course.id, mode_slug=CourseMode.AUDIT)
                CourseModeFactory.create(course_id=course.id, mode_slug=CourseMode.VERIFIED)
                course_ids.append(course.id)

        self.setup_user(self.audit_user)

        # These query counts were found empirically
        query_counts = [63, 50, 50, 50, 50, 50, 50, 50, 50, 50, 20]
        ordered_course_ids = sorted([str(cid) for cid in (course_ids + [c.id for c in self.courses])])

        self.clear_caches()

        for page in range(1, 12):
            RequestCache.clear_all_namespaces()
            with self.assertNumQueries(query_counts[page - 1]):
                response = self.verify_response(params={'page': page, 'page_size': 30})

                self.assertIn('results', response.data)
                self.assertEqual(response.data['pagination']['count'], 303)
                self.assertEqual(len(response.data['results']), 30 if page < 11 else 3)
                self.assertEqual(
                    [c['id'] for c in response.data['results']],
                    ordered_course_ids[(page - 1) * 30:page * 30]
                )
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:51,代码来源:test_views.py

示例10: persistent_grades_feature_flags

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
def persistent_grades_feature_flags(
        global_flag,
        enabled_for_all_courses=False,
        course_id=None,
        enabled_for_course=False
):
    """
    Most test cases will use a single call to this manager,
    as they need to set the global setting and the course-specific
    setting for a single course.
    """
    RequestCache.clear_all_namespaces()
    PersistentGradesEnabledFlag.objects.create(enabled=global_flag, enabled_for_all_courses=enabled_for_all_courses)
    if course_id:
        CoursePersistentGradesFlag.objects.create(course_id=course_id, enabled=enabled_for_course)
    yield
开发者ID:edx,项目名称:edx-platform,代码行数:18,代码来源:utils.py

示例11: clear_caches

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
    def clear_caches(cls):
        """
        Clear all of the caches defined in settings.CACHES.
        """
        # N.B. As of 2016-04-20, Django won't return any caches
        # from django.core.cache.caches.all() that haven't been
        # accessed using caches[name] previously, so we loop
        # over our list of overridden caches, instead.
        for cache in settings.CACHES:
            caches[cache].clear()

        # The sites framework caches in a module-level dictionary.
        # Clear that.
        sites.models.SITE_CACHE.clear()

        RequestCache.clear_all_namespaces()
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:18,代码来源:utils.py

示例12: setUp

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
 def setUp(self):
     """
     Set up test data
     """
     super(ProgramCourseEnrollmentModelTests, self).setUp()
     RequestCache.clear_all_namespaces()
     self.user = UserFactory.create()
     self.program_uuid = uuid4()
     self.program_enrollment = ProgramEnrollment.objects.create(
         user=self.user,
         external_user_key='abc',
         program_uuid=self.program_uuid,
         curriculum_uuid=uuid4(),
         status='enrolled'
     )
     self.course_key = CourseKey.from_string(generate_course_run_key())
     CourseOverviewFactory(id=self.course_key)
开发者ID:edx,项目名称:edx-platform,代码行数:19,代码来源:test_models.py

示例13: test_caching_org

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
    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()

        RequestCache.clear_all_namespaces()

        # Check that the org value is not retrieved from cache after save
        with self.assertNumQueries(2):
            self.assertTrue(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):
            self.assertTrue(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):
            self.assertFalse(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):
            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()

        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(org=course.org).enabled)
开发者ID:edx,项目名称:edx-platform,代码行数:46,代码来源:test_models.py

示例14: dump_courses_to_neo4j

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
    def dump_courses_to_neo4j(self, credentials, override_cache=False):
        """
        Method that iterates through a list of courses in a modulestore,
        serializes them, then submits tasks to write them to neo4j.
        Arguments:
            credentials (dict): the necessary credentials to connect
              to neo4j and create a py2neo `Graph` object
            override_cache: serialize the courses even if they'be been recently
                serialized

        Returns: two lists--one of the courses that were successfully written
            to neo4j and one of courses that were not.
        """

        total_number_of_courses = len(self.course_keys)

        submitted_courses = []
        skipped_courses = []

        graph = authenticate_and_create_graph(credentials)

        for index, course_key in enumerate(self.course_keys):
            # first, clear the request cache to prevent memory leaks
            RequestCache.clear_all_namespaces()

            log.info(
                "Now submitting %s for export to neo4j: course %d of %d total courses",
                course_key,
                index + 1,
                total_number_of_courses,
            )

            if not (override_cache or should_dump_course(course_key, graph)):
                log.info("skipping submitting %s, since it hasn't changed", course_key)
                skipped_courses.append(six.text_type(course_key))
                continue

            dump_course_to_neo4j.apply_async(
                args=[six.text_type(course_key), credentials],
            )
            submitted_courses.append(six.text_type(course_key))

        return submitted_courses, skipped_courses
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:45,代码来源:tasks.py

示例15: test_request_context_caching

# 需要导入模块: from edx_django_utils.cache import RequestCache [as 别名]
# 或者: from edx_django_utils.cache.RequestCache import clear_all_namespaces [as 别名]
    def test_request_context_caching(self):
        """
        Test that the RequestContext is cached in the RequestCache.
        """
        with patch('edxmako.request_context.get_current_request', return_value=None):
            # requestcontext should be None, because the cache isn't filled
            self.assertIsNone(get_template_request_context())

        with patch('edxmako.request_context.get_current_request', return_value=self.request):
            # requestcontext should not be None, and should fill the cache
            self.assertIsNotNone(get_template_request_context())

        mock_get_current_request = Mock()
        with patch('edxmako.request_context.get_current_request', mock_get_current_request):
            # requestcontext should not be None, because the cache is filled
            self.assertIsNotNone(get_template_request_context())
        mock_get_current_request.assert_not_called()

        RequestCache.clear_all_namespaces()

        with patch('edxmako.request_context.get_current_request', return_value=None):
            # requestcontext should be None, because the cache isn't filled
            self.assertIsNone(get_template_request_context())
开发者ID:albluqmun,项目名称:edx-platform,代码行数:25,代码来源:tests.py


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