Here are the examples of the python api django.core.cache.cache.clear taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
148 Examples
3
Example 1
Project: edx-platform Source File: test_api.py
def test_caching_no_restricted_courses(self):
RestrictedCourse.objects.all().delete()
cache.clear()
with self.assertNumQueries(1):
embargo_api.check_course_access(self.course.id, user=self.user, ip_address='0.0.0.0')
with self.assertNumQueries(0):
embargo_api.check_course_access(self.course.id, user=self.user, ip_address='0.0.0.0')
3
Example 2
Project: django-test-addons Source File: mixins.py
def _post_teardown(self):
super(MongoTestMixin, self)._post_teardown()
connection = mongoengine.connection.get_connection()
connection.drop_database(self.MONGO_DB_SETTINGS['db'])
utils.disconnect()
if self.CLEAR_CACHE:
cache.clear()
3
Example 3
Project: django-scribbler Source File: test_templatetags.py
@skipIf(not CACHE_TIMEOUT, "Caching is disabled.")
def test_cache_lookup_miss(self):
"Scribbles not in the DB should also be cached to prevent unnecessary lookup."
self.scribble.delete()
cache.clear()
with self.assertNumQueries(1):
# Render twice but should be one DB lookup
result = self.render_template_tag(slug='"sidebar"')
self.assertTrue('<p>Default.</p>' in result)
result = self.render_template_tag(slug='"sidebar"')
self.assertTrue('<p>Default.</p>' in result)
3
Example 4
def setUp(self):
self.other_dummy = OtherCachedDummyModel.objects.create()
self.dummy = CachedDummyModel.objects.create()
self.dummy.related = self.other_dummy
self.dummy.save()
cache.clear()
3
Example 5
def tearDown(self):
if django.VERSION >= (1, 8):
self.overrider.disable()
cache.clear() # BlogPage URLs are stored in cache
super(BlogPageTests, self).tearDown()
3
Example 6
def tearDown(self):
'''
Reset settings
'''
del os.environ['RECAPTCHA_TESTING']
cache.clear()
# Clear MEDIA_ROOT folder
shutil.rmtree(self.media_root)
3
Example 7
Project: aldryn-newsblog Source File: test_plugins.py
def test_featured_articles_plugin_unpublished_app_page(self):
with override('de'):
articles = [self.create_article(is_featured=True)
for _ in range(3)]
response = self.client.get(self.plugin_page.get_absolute_url())
for article in articles:
self.assertContains(response, article.title)
self.page.unpublish('de')
cache.clear()
response = self.client.get(self.plugin_page.get_absolute_url())
for article in articles:
self.assertNotContains(response, article.title)
3
Example 8
Project: shuup Source File: test_page_view.py
@pytest.mark.django_db
def test_multilanguage_page_404_no_xlate(rf):
# https://github.com/edoburu/django-parler/issues/50
cache.clear() # this is here, because parler cache is enabled and tests use same pk with page
page = create_multilanguage_page(eternal=True, url="no_content",
languages=("udm",)) # create page with udm language
get_default_shop()
request = apply_request_middleware(rf.get("/"))
with translation.override("fi"): # change language of the page to fi
view_func = PageView.as_view()
with pytest.raises(Http404):
response = view_func(request, url="no_content-udm") # Using Udmurt URL, but xlate is Finnish . . .
assert response.status_code == 404 # ... should 404
3
Example 9
Project: ANALYSE Source File: tests.py
def setUp(self):
self.email = '[email protected]'
self.pw = 'xyz'
self.username = 'testuser'
self.client = AjaxEnabledTestClient()
# clear the cache so ratelimiting won't affect these tests
cache.clear()
3
Example 10
Project: splunk-webframework Source File: base.py
def setUp(self):
self.base_url = '%s://%s' % (self.protocol, self.domain)
self.old_Site_meta_installed = Site._meta.installed
cache.clear()
# Create an object for sitemap content.
TestModel.objects.create(name='Test Object')
3
Example 11
def flush_cache(hard=True):
from cachebot.models import CacheBotSignals
from cachebot.signals import cache_signals
CacheBotSignals.objects.all().delete()
cache_signals.local_signals = {}
if hard:
cache.clear()
else:
cache.version = int(time()*10000)
3
Example 12
Project: django-oscar Source File: catalogue_tests.py
@ignore_deprecation_warnings
def test_can_chop_off_last_part_of_url(self):
# We cache category URLs, which normally is a safe thing to do, as
# the primary key stays the same and ProductCategoryView only looks
# at the key any way.
# But this test chops the URLs, and hence relies on the URLs being
# correct. So in this case, we start with a clean cache to ensure
# our URLs are correct.
cache.clear()
child_category = self.category.add_child(name='Cool products')
full_url = child_category.get_absolute_url()
chopped_url = full_url.rsplit('/', 2)[0]
parent_url = self.category.get_absolute_url()
response = self.app.get(chopped_url).follow() # fails if no redirect
self.assertTrue(response.url.endswith(parent_url))
3
Example 13
def setUp(self):
"""
Reset the cache so that no throttles will be active
"""
cache.clear()
self.factory = APIRequestFactory()
3
Example 14
def setUp(self):
super(AuthTestCase, self).setUp()
self.email = '[email protected]'
self.pw = 'xyz'
self.username = 'testuser'
self.client = AjaxEnabledTestClient()
# clear the cache so ratelimiting won't affect these tests
cache.clear()
3
Example 15
Project: django-security Source File: tests.py
def test_counters(self):
cache.clear()
increment_counters(username="foo", ip="127.0.0.1")
increment_counters(username="foo")
self.assertEqual(attempt_count("username", "foo"), 2)
self.assertEqual(attempt_count("ip", "127.0.0.1"), 1)
self.assertEqual(attempt_count("username", "baz"), 0)
reset_counters(username="foo", ip="127.0.0.1")
self.assertEqual(attempt_count("username", "foo"), 0)
self.assertEqual(attempt_count("ip", "127.0.0.1"), 0)
cache.clear()
3
Example 16
def tearDown(self):
"""
Do a proper cleanup, delete everything what is preventing us from
clean environment for tests.
:return: None
"""
self.app_config.delete()
self.reset_all()
cache.clear()
3
Example 17
Project: django-package-monitor Source File: test_pypi.py
@mock.patch('requests.get', mock_get)
def test_data_caching(self):
cache.clear()
key = pypi.cache_key('django')
package = pypi.Package('django')
self.assertIsNone(cache.get(key))
self.assertEqual(package.data(), self.test_data)
self.assertEqual(cache.get(key), self.package.data())
3
Example 18
Project: sentry Source File: cases.py
def _pre_setup(self):
super(BaseTestCase, self)._pre_setup()
cache.clear()
ProjectOption.objects.clear_local_cache()
GroupMeta.objects.clear_local_cache()
3
Example 19
def setUp(self):
"""Set up this test case."""
super(DiffViewerFileAttachmentTests, self).setUp()
# The diff viewer's caching breaks the result of these tests,
# so be sure we clear before each one.
cache.clear()
3
Example 20
def _pre_setup(self):
"""Disable transaction methods, and clear some globals."""
# Repeat stuff from TransactionTestCase, because I'm not calling its
# _pre_setup, because that would load fixtures again.
cache.cache.clear()
settings.TEMPLATE_DEBUG = settings.DEBUG = False
test.testcases.disable_transaction_methods()
self.client = self.client_class()
self._urlconf_setup()
mail.outbox = []
# Clear site cache in case somebody's mutated Site objects and then
# cached the mutated stuff:
from django.contrib.sites.models import Site
Site.objects.clear_cache()
3
Example 21
Project: drf-extensions Source File: plugins.py
def _monkeypatch_testcase(self):
old_run = TestCase.run
def new_run(*args, **kwargs):
cache.clear()
return old_run(*args, **kwargs)
TestCase.run = new_run
3
Example 22
def setUp(self):
cache.clear()
# ensure records are published to cache
Issuer.cached.get(slug='test-issuer')
Issuer.cached.get(pk=2)
BadgeClass.cached.get(slug='badge-of-testing')
BadgeClass.cached.get(pk=1)
BadgeInstance.cached.get(slug='92219015-18a6-4538-8b6d-2b228e47b8aa')
pass
3
Example 23
def tearDown(self):
super(RepositoryTests, self).tearDown()
cache.clear()
self.scmtool_cls.get_file = self.old_get_file
self.scmtool_cls.file_exists = self.old_file_exists
3
Example 24
Project: django-nose Source File: testcases.py
def _pre_setup(self):
"""Disable transaction methods, and clear some globals."""
# Repeat stuff from TransactionTestCase, because I'm not calling its
# _pre_setup, because that would load fixtures again.
cache.cache.clear()
settings.TEMPLATE_DEBUG = settings.DEBUG = False
test.testcases.disable_transaction_methods()
self.client = self.client_class()
# self._fixture_setup()
self._urlconf_setup()
mail.outbox = []
# Clear site cache in case somebody's mutated Site objects and then
# cached the mutated stuff:
from django.contrib.sites.models import Site
Site.objects.clear_cache()
3
Example 25
Project: madewithwagtail Source File: signals.py
@receiver(post_save)
def post_model_save(sender, instance, **kwargs):
"""
Clear cache when any kind of Model is saved
"""
cache.clear()
3
Example 26
def handle(self, *args, **kwargs):
"""
Process the command.
"""
cache.clear()
self.stdout.write("Cache has been completely cleared.")
3
Example 27
Project: django-parler Source File: test_model_inheritance.py
def test_save_two_levels(self):
x = Level2(l1_title='LEVEL1', l2_title='LEVEL2', id=2)
x.save()
cache.clear()
# See if fetching the object again works
x = Level2.objects.get(pk=x.pk)
self.assertEqual(x.l1_title, "LEVEL1")
self.assertEqual(x.l2_title, "LEVEL2")
# check that the translations exist after saving
translation = Level2._parler_meta[-1].model.objects.get(master=x)
self.assertEqual(translation.l2_title, "LEVEL2")
3
Example 28
def handle(self, *args, **options):
from django.conf import settings
from tendenci.apps.site_settings.models import Setting
from django.core.cache import cache
setting = Setting.objects.get(scope='module', scope_category='theme_editor')
setting.set_value(settings.SITE_THEME)
setting.save()
cache.clear()
3
Example 29
Project: django-ormcache Source File: test_queryset.py
def test_all_deferred_fields(self):
# This should not cache lesson since it contains deferred fields
CachedDummyModel.objects.only().get(pk=self.instance1.pk)
with self.assertNumQueries(1):
title = CachedDummyModel.objects.get(pk=self.instance1.pk).title
self.assertEqual(self.instance1.title, title)
cache.clear()
3
Example 30
def setUp(self):
"""
Setup some initial users
"""
self.user_pw = 'test'
self.user_bob = self.create_user('bob', '[email protected]', self.user_pw)
self.user_steve = self.create_user('steve', '[email protected]', self.user_pw)
self.user_susan = self.create_user('susan', '[email protected]', self.user_pw)
self.user_amy = self.create_user('amy', '[email protected]', self.user_pw)
cache.clear()
3
Example 31
def setUp(self):
self.related_instance = OtherCachedDummyModel.objects.create()
self.instance = CachedDummyModel.objects.create(
related=self.related_instance)
cache.clear()
3
Example 32
def setUp(self):
user_model = get_user_model()
self.user = user_model.objects.create_user(username='test', password='a')
self.user.is_superuser = True
self.user.is_staff = True
self.user.save()
cache.clear()
3
Example 33
def setUp(self):
super(EmbargoCheckAccessApiTests, self).setUp()
self.course = CourseFactory.create()
self.user = UserFactory.create()
self.restricted_course = RestrictedCourse.objects.create(course_key=self.course.id)
Country.objects.create(country='US')
Country.objects.create(country='IR')
Country.objects.create(country='CU')
# Clear the cache to prevent interference between tests
cache.clear()
3
Example 34
Project: bitnodes-hardware Source File: tasks.py
@celeryd_init.connect
def startup_task(sender=None, conf=None, **kwargs):
cache.clear()
bandwidth_task()
system_info_task()
exchange_rate_task()
3
Example 35
Project: open-context-py Source File: finalize.py
def make_outcomes(self):
""" Makes a dictionary object of process outcomes """
outcomes = LastUpdatedOrderedDict()
outcomes['ok'] = self.ok
outcomes['start'] = self.start_row
outcomes['end'] = self.end_row
outcomes['row_count'] = self.row_count
outcomes['done'] = self.done
outcomes['done_stage_num'] = self.act_process_num
outcomes['total_stages'] = len(self.active_processes)
outcomes['done_stage'] = self.active_processes[self.act_process_num]
if self.done is False:
outcomes['next_stage'] = self.active_processes[self.next_process_num]
else:
outcomes['done_stage_num'] = outcomes['total_stages']
outcomes['next_stage'] = 'All completed'
# now clear the cache a change was made
cache.clear()
return outcomes
3
Example 36
def cache_clear():
""" Clear cache
If not working try: (memcached only) cache._cache.flush_all()
:return: None
"""
cache.clear()
3
Example 37
Project: aldryn-newsblog Source File: test_plugins.py
def _test_plugin_languages_with_article(self, article):
"""Set up conditions to test plugin languages edge cases"""
# Add 'de' translation to one of the articles
title_de = 'title-de'
title_en = article.title
article.set_current_language('de')
article.title = title_de
article.save()
# Unpublish page with newsblog apphook
self.page.unpublish('en')
cache.clear()
response = self.client.get(self.plugin_page.get_absolute_url())
# This article should not be visible on 'en' page/plugin
self.assertNotContains(response, title_en)
3
Example 38
Project: coursys Source File: testcase.py
def _pre_setup(self):
"""Disable transaction methods, and clear some globals."""
# Repeat stuff from TransactionTestCase, because I'm not calling its
# _pre_setup, because that would load fixtures again.
cache.cache.clear()
settings.TEMPLATE_DEBUG = settings.DEBUG = False
self.client = self.client_class()
#self._fixture_setup()
self._urlconf_setup()
mail.outbox = []
# Clear site cache in case somebody's mutated Site objects and then
# cached the mutated stuff:
from django.contrib.sites.models import Site
Site.objects.clear_cache()
3
Example 39
Project: aldryn-newsblog Source File: test_plugins.py
def test_latest_articles_plugin_unpublished_app_page(self):
with override('de'):
articles = [self.create_article() for _ in range(3)]
response = self.client.get(self.plugin_page.get_absolute_url())
for article in articles:
self.assertContains(response, article.title)
self.page.unpublish('de')
cache.clear()
response = self.client.get(self.plugin_page.get_absolute_url())
for article in articles:
self.assertNotContains(response, article.title)
3
Example 40
Project: django-scribbler Source File: test_templatetags.py
@skipIf(not CACHE_TIMEOUT, "Caching is disabled.")
def test_cache_scribble_lookup(self):
"DB lookups should be cached."
cache.clear()
with self.assertNumQueries(1):
# Render twice but should be one DB lookup
result = self.render_template_tag(slug='"sidebar"')
self.assertTrue('<p>Scribble content.</p>' in result)
result = self.render_template_tag(slug='"sidebar"')
self.assertTrue('<p>Scribble content.</p>' in result)
3
Example 41
Project: database-as-a-service Source File: test_disk_offering.py
def create_basic_disks(self):
DiskOffering.objects.all().delete()
cache.clear()
self.bigger = DiskOfferingFactory()
self.bigger.size_kb *= 30
self.bigger.available_size_kb *= 30
self.bigger.save()
self.medium = DiskOfferingFactory()
self.medium.size_kb *= 20
self.medium.available_size_kb *= 20
self.medium.save()
self.smaller = DiskOfferingFactory()
self.smaller.size_kb *= 10
self.smaller.available_size_kb *= 10
self.smaller.save()
3
Example 42
Project: django-rest-messaging Source File: test_middleware.py
def test_middleware_existing_participant(self):
""" This test ensures the middleware creates the Participant corresponding to request.user, if not done yet. """
# we ensure the cache is empty
cache.clear()
# we have a participant
Participant.objects.create(id=self.request.user.id)
with self.assertNumQueries(1):
self.middleware.process_view(request=self.request, callback=None, callback_args=None, callback_kwargs=None)
self.assertEqual(self.request.rest_messaging_participant.id, self.request.user.id)
# we rehit the middleware, rest_messaging_participant has been cached
with self.assertNumQueries(0):
self.middleware.process_view(request=self.request, callback=None, callback_args=None, callback_kwargs=None)
3
Example 43
Project: test-utils Source File: __init__.py
def _pre_setup(self):
# allow others to prepare
signals.pre_setup.send(sender=self.__class__)
cache.cache.clear()
settings.CACHE_COUNT_TIMEOUT = None
settings.TEMPLATE_DEBUG = settings.DEBUG = False
super(BaseTestCase, self)._pre_setup()
3
Example 44
Project: django-scribbler Source File: test_templatetags.py
@skipIf(not CACHE_TIMEOUT, "Caching is disabled.")
def test_cached_on_save(self):
"Scribbles are cached on their save."
cache.clear()
other_scribble = self.create_scribble(
url='/foo/', slug='header',
content='<p>New content.</p>'
)
with self.assertNumQueries(0):
# Render twice but should be one DB lookup
result = self.render_template_tag(slug='"header"')
self.assertTrue('<p>New content.</p>' in result)
3
Example 45
@contextmanager
def fake_time(timestamp):
"""A context manager which causes all requests having the specified
timestamp, regardless of the real wall clock time."""
cache.clear()
FakeTimeMiddleware._fake_timestamp.value = timestamp
yield
del FakeTimeMiddleware._fake_timestamp.value
3
Example 46
Project: django-rest-messaging Source File: test_middleware.py
def test_middleware_new_participant(self):
""" This test ensures the middleware creates the Participant corresponding to request.user, if not done yet. """
# we ensure the cache is empty
cache.clear()
# we have no participant yet
self.assertRaises(ObjectDoesNotExist, Participant.objects.get, id=self.request.user.id)
with self.assertNumQueries(2):
self.middleware.process_view(request=self.request, callback=None, callback_args=None, callback_kwargs=None)
# the user has been created
self.assertTrue(Participant.objects.get(id=self.request.user.id))
self.assertEqual(self.request.rest_messaging_participant.id, self.request.user.id)
# we rehit the middleware, rest_messaging_participant has been cached
with self.assertNumQueries(0):
self.middleware.process_view(request=self.request, callback=None, callback_args=None, callback_kwargs=None)
3
Example 47
Project: django-clear-cache Source File: clear_cache.py
def handle(self, *args, **kwargs):
try:
assert settings.CACHES
cache.clear()
self.stdout.write('Your cache has been cleared!\n')
except AttributeError:
raise CommandError('You have no cache configured!\n')
3
Example 48
def setUp(self):
super(TestCase, self).setUp()
initialize()
self._local_sites = {}
# Clear the cache so that previous tests don't impact this one.
cache.clear()
3
Example 49
Project: taiga-back Source File: test_throwttling.py
def test_anonimous_throttling_policy(client, settings):
f.create_project()
url = reverse("projects-list")
with mock.patch(anon_rate_path) as anon_rate, \
mock.patch(user_rate_path) as user_rate, \
mock.patch(import_rate_path) as import_rate:
anon_rate.return_value = "2/day"
user_rate.return_value = "4/day"
import_rate.return_value = "7/day"
cache.clear()
response = client.json.get(url)
assert response.status_code == 200
response = client.json.get(url)
assert response.status_code == 200
response = client.json.get(url)
assert response.status_code == 429
3
Example 50
Project: django-parler Source File: test_query_count.py
def test_model_cache_queries(self):
"""
Test that the ``_translations_cache`` works.
"""
cache.clear()
with override_parler_settings(PARLER_ENABLE_CACHING=False):
qs = SimpleModel.objects.all()
self.assertNumTranslatedQueries(1 + len(self.country_list), qs)
self.assertNumTranslatedQueries(0, qs) # All should be cached on the QuerySet and object now.
qs = SimpleModel.objects.prefetch_related('translations')
self.assertNumTranslatedQueries(2, qs)
self.assertNumTranslatedQueries(0, qs) # All should be cached on the QuerySet and object now.