本文整理汇总了Python中request_cache.middleware.RequestCache.clear_request_cache方法的典型用法代码示例。如果您正苦于以下问题:Python RequestCache.clear_request_cache方法的具体用法?Python RequestCache.clear_request_cache怎么用?Python RequestCache.clear_request_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类request_cache.middleware.RequestCache
的用法示例。
在下文中一共展示了RequestCache.clear_request_cache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_course_waffle_flag
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def test_course_waffle_flag(self, data):
"""
Tests various combinations of a flag being set in waffle and overridden
for a course.
"""
RequestCache.clear_request_cache()
with patch.object(WaffleFlagCourseOverrideModel, 'override_value', return_value=data['course_override']):
with override_flag(self.NAMESPACED_FLAG_NAME, active=data['waffle_enabled']):
# check twice to test that the result is properly cached
self.assertEqual(self.TEST_COURSE_FLAG.is_enabled(self.TEST_COURSE_KEY), data['result'])
self.assertEqual(self.TEST_COURSE_FLAG.is_enabled(self.TEST_COURSE_KEY), data['result'])
# result is cached, so override check should happen once
WaffleFlagCourseOverrideModel.override_value.assert_called_once_with(
self.NAMESPACED_FLAG_NAME,
self.TEST_COURSE_KEY
)
# check flag for a second course
if data['course_override'] == WaffleFlagCourseOverrideModel.ALL_CHOICES.unset:
# When course override wasn't set for the first course, the second course will get the same
# cached value from waffle.
self.assertEqual(self.TEST_COURSE_FLAG.is_enabled(self.TEST_COURSE_2_KEY), data['waffle_enabled'])
else:
# When course override was set for the first course, it should not apply to the second
# course which should get the default value of False.
self.assertEqual(self.TEST_COURSE_FLAG.is_enabled(self.TEST_COURSE_2_KEY), False)
示例2: test_grades_csv
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def test_grades_csv(self):
self.course.enable_ccx = True
RequestCache.clear_request_cache()
url = reverse(
'ccx_grades_csv',
kwargs={'course_id': self.ccx_key}
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
# Are the grades downloaded as an attachment?
self.assertEqual(
response['content-disposition'],
'attachment'
)
rows = response.content.strip().split('\r')
headers = rows[0]
records = dict()
for i in range(1, len(rows)):
data = dict(zip(headers.strip().split(','), rows[i].strip().split(',')))
records[data['username']] = data
student_data = records[self.student.username] # pylint: disable=no-member
self.assertNotIn('HW 04', student_data)
self.assertEqual(student_data['HW 01'], '0.75')
self.assertEqual(student_data['HW 02'], '0.5')
self.assertEqual(student_data['HW 03'], '0.25')
self.assertEqual(student_data['HW Avg'], '0.5')
示例3: test_grades_csv
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def test_grades_csv(self):
self.course.enable_ccx = True
RequestCache.clear_request_cache()
url = reverse(
'ccx_grades_csv',
kwargs={'course_id': self.ccx_key}
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
# Are the grades downloaded as an attachment?
self.assertEqual(
response['content-disposition'],
'attachment'
)
rows = response.content.strip().split('\r')
headers = rows[0]
# picking first student records
data = dict(zip(headers.strip().split(','), rows[1].strip().split(',')))
self.assertNotIn('HW 04', data)
self.assertEqual(data['HW 01'], '0.75')
self.assertEqual(data['HW 02'], '0.5')
self.assertEqual(data['HW 03'], '0.25')
self.assertEqual(data['HW Avg'], '0.5')
示例4: instrument_course_progress_render
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [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_request_cache()
# 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'):
with self.assertNumQueries(0, using='student_module_history'):
with self.assertMongoCallCount(mongo_reads):
with self.assertXBlockInstantiations(1):
self.grade_course(course_key)
示例5: test_get_template_path
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [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_request_cache()
# 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")
示例6: test_undefined_waffle_flag
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def test_undefined_waffle_flag(self, data):
"""
Test flag with various defaults provided for undefined waffle flags.
"""
RequestCache.clear_request_cache()
test_course_flag = CourseWaffleFlag(
self.TEST_NAMESPACE,
self.FLAG_NAME,
flag_undefined_default=data['flag_undefined_default']
)
with patch.object(
WaffleFlagCourseOverrideModel,
'override_value',
return_value=WaffleFlagCourseOverrideModel.ALL_CHOICES.unset
):
# check twice to test that the result is properly cached
self.assertEqual(test_course_flag.is_enabled(self.TEST_COURSE_KEY), data['result'])
self.assertEqual(test_course_flag.is_enabled(self.TEST_COURSE_KEY), data['result'])
# result is cached, so override check should happen once
WaffleFlagCourseOverrideModel.override_value.assert_called_once_with(
self.NAMESPACED_FLAG_NAME,
self.TEST_COURSE_KEY
)
示例7: instrument_course_progress_render
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def instrument_course_progress_render(self, course_width, enable_ccx, queries, reads, xblocks):
"""
Renders the progress page, instrumenting Mongo reads and SQL queries.
"""
self.setup_course(course_width, enable_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:
get_cache(cache).clear()
# Refill the metadata inheritance cache
modulestore().get_course(self.course.id, depth=None)
# We clear the request cache to simulate a new request in the LMS.
RequestCache.clear_request_cache()
# Reset the list of provider classes, so that our django settings changes
# can actually take affect.
OverrideFieldData.provider_classes = None
with self.assertNumQueries(queries):
with check_mongo_calls(reads):
with check_sum_of_calls(XBlock, ['__init__'], xblocks, xblocks, include_arguments=False):
self.grade_course(self.course)
示例8: test_request_cached_with_caches_despite_changing_wrapped_result
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def test_request_cached_with_caches_despite_changing_wrapped_result(self):
"""
Ensure that after caching a result, we always send it back, even if the underlying result changes.
"""
RequestCache.clear_request_cache()
to_be_wrapped = Mock()
to_be_wrapped.side_effect = [1, 2, 3]
self.assertEqual(to_be_wrapped.call_count, 0)
def mock_wrapper(*args, **kwargs):
"""Simple wrapper to let us decorate our mock."""
return to_be_wrapped(*args, **kwargs)
wrapped = request_cached(mock_wrapper)
result = wrapped()
self.assertEqual(result, 1)
self.assertEqual(to_be_wrapped.call_count, 1)
result = wrapped()
self.assertEqual(result, 1)
self.assertEqual(to_be_wrapped.call_count, 1)
direct_result = mock_wrapper()
self.assertEqual(direct_result, 2)
self.assertEqual(to_be_wrapped.call_count, 2)
result = wrapped()
self.assertEqual(result, 1)
self.assertEqual(to_be_wrapped.call_count, 2)
direct_result = mock_wrapper()
self.assertEqual(direct_result, 3)
self.assertEqual(to_be_wrapped.call_count, 3)
示例9: test_setting_override
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def test_setting_override(self, is_enabled, override_choice, expected_result):
RequestCache.clear_request_cache()
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)
示例10: test_setting_override_multiple_times
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def test_setting_override_multiple_times(self):
RequestCache.clear_request_cache()
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)
示例11: handle
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def handle(self, *args, **options): # pylint: disable=unused-argument
"""
Iterates through each course, serializes them into graphs, and saves
those graphs to neo4j.
"""
# first, make sure that there's a valid neo4j configuration
if settings.NEO4J_CONFIG is None:
raise CommandError(
"No neo4j configuration (NEO4J_CONFIG) defined in lms.auth.json."
)
auth_params = ["{host}:{https_port}", "{user}", "{password}"]
authenticate(*[param.format(**settings.NEO4J_CONFIG) for param in auth_params])
graph = Graph(**settings.NEO4J_CONFIG)
mss = ModuleStoreSerializer()
total_number_of_courses = len(mss.all_courses)
for index, course in enumerate(mss.all_courses):
# first, clear the request cache to prevent memory leaks
RequestCache.clear_request_cache()
log.info(
"Now exporting %s to neo4j: course %d of %d total courses",
course.id,
index + 1,
total_number_of_courses
)
nodes, relationships = mss.serialize_course(course.id)
log.info(
"%d nodes and %d relationships in %s",
len(nodes),
len(relationships),
course.id
)
transaction = graph.begin()
try:
# first, delete existing course
transaction.run(
"MATCH (n:item) WHERE n.course_key='{}' DETACH DELETE n".format(
six.text_type(course.id)
)
)
# now, re-add it
self.add_to_transaction(nodes, transaction)
self.add_to_transaction(relationships, transaction)
transaction.commit()
except Exception: # pylint: disable=broad-except
log.exception(
"Error trying to dump course %s to neo4j, rolling back",
six.text_type(course.id)
)
transaction.rollback()
示例12: lti_consumer_fields_editing_flag
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [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_request_cache()
CourseEditLTIFieldsEnabledFlag.objects.create(course_id=course_id, enabled=enabled_for_course)
yield
示例13: assert_access_to_gated_content
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def assert_access_to_gated_content(self, user, expected_access):
"""
Verifies access to gated content for the given user is as expected.
"""
# clear the request cache to flush any cached access results
RequestCache.clear_request_cache()
# access to gating content (seq1) remains constant
self.assertTrue(bool(has_access(user, 'load', self.seq1, self.course.id)))
# access to gated content (seq2) is as expected
self.assertEquals(bool(has_access(user, 'load', self.seq2, self.course.id)), expected_access)
示例14: test_gradebook
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [as 别名]
def test_gradebook(self):
self.course.enable_ccx = True
RequestCache.clear_request_cache()
url = reverse("ccx_gradebook", kwargs={"course_id": self.ccx_key})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
# Max number of student per page is one. Patched setting MAX_STUDENTS_PER_PAGE_GRADE_BOOK = 1
self.assertEqual(len(response.mako_context["students"]), 1) # pylint: disable=no-member
student_info = response.mako_context["students"][0] # pylint: disable=no-member
self.assertEqual(student_info["grade_summary"]["percent"], 0.5)
self.assertEqual(student_info["grade_summary"]["grade_breakdown"][0]["percent"], 0.5)
self.assertEqual(len(student_info["grade_summary"]["section_breakdown"]), 4)
示例15: clear_caches
# 需要导入模块: from request_cache.middleware import RequestCache [as 别名]
# 或者: from request_cache.middleware.RequestCache import clear_request_cache [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_request_cache()