django.core.cache.cache.clear

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 7

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')

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()

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)

Example 4

Project: django-ormcache Source File: test_queryset.py
Function: set_up
    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()

Example 5

Project: django-fluent-blogs Source File: test_blogpage.py
Function: tear_down
    def tearDown(self):
        if django.VERSION >= (1, 8):
            self.overrider.disable()

        cache.clear()  # BlogPage URLs are stored in cache
        super(BlogPageTests, self).tearDown()

Example 6

Project: wger Source File: base_testcase.py
Function: tear_down
    def tearDown(self):
        '''
        Reset settings
        '''
        del os.environ['RECAPTCHA_TESTING']
        cache.clear()

        # Clear MEDIA_ROOT folder
        shutil.rmtree(self.media_root)

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)

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

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()

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')

Example 11

Project: django-cachebot Source File: utils.py
Function: flush_cache
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)

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))

Example 13

Project: django-rest-framework Source File: test_throttling.py
Function: set_up
    def setUp(self):
        """
        Reset the cache so that no throttles will be active
        """
        cache.clear()
        self.factory = APIRequestFactory()

Example 14

Project: edx-platform Source File: tests.py
Function: set_up
    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()

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()

Example 16

Project: aldryn-events Source File: base.py
Function: tear_down
    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()

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())

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()

Example 19

Project: reviewboard Source File: tests.py
Function: set_up
    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()

Example 20

Project: test-utils Source File: __init__.py
Function: pre_setup
    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()

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

Example 22

Project: badgr-server Source File: tests.py
Function: set_up
    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

Example 23

Project: reviewboard Source File: test_repository.py
Function: tear_down
    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

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()

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()

Example 26

Project: 2buntu-blog Source File: clearcache.py
Function: handle
    def handle(self, *args, **kwargs):
        """
        Process the command.
        """
        cache.clear()
        self.stdout.write("Cache has been completely cleared.")

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")

Example 28

Project: tendenci Source File: theme_editor_init_setting.py
Function: handle
    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()

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()

Example 30

Project: django-friendship Source File: tests.py
Function: set_up
    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()

Example 31

Project: django-ormcache Source File: test_utils.py
Function: set_up
    def setUp(self):
        self.related_instance = OtherCachedDummyModel.objects.create()
        self.instance = CachedDummyModel.objects.create(
            related=self.related_instance)

        cache.clear()

Example 32

Project: django-cached_authentication_middleware Source File: tests.py
Function: set_up
    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()

Example 33

Project: edx-platform Source File: test_api.py
Function: set_up
    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()

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()

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

Example 36

Project: django-ninecms Source File: status.py
Function: cache_clear
def cache_clear():
    """ Clear cache
    If not working try: (memcached only) cache._cache.flush_all()
    :return: None
    """
    cache.clear()

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)

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()

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)

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)

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()

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)

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()

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)

Example 45

Project: oioioi Source File: __init__.py
Function: fake_time
@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

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)

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')

Example 48

Project: reviewboard Source File: testcase.py
Function: set_up
    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()

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

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.
See More Examples - Go to Next Page
Page 1 Selected Page 2 Page 3