コード例 #1
0
ファイル: tests.py プロジェクト: mapc1508/firecares
    def test_firedepartment_detail_page_caching(self):
        # Requires having something *other* than the DummyCache in order test caching
        call_command('loaddata', 'firecares/firestation/fixtures/test_government_unit_association.json')
        # need to create the quartile views in order for the dept detail page to be retrieved
        create_quartile_views(None)

        c = Client()
        fd = FireDepartment.objects.get(pk=86610)

        # Login and make sure that we get a 200 back from the govt unit association update page
        c.login(**{'username': '******', 'password': '******'})
        response = c.get(reverse('firedepartment_update_government_units', args=[fd.pk]))
        self.assertEqual(response.status_code, 200)

        cache = caches['default']
        # remove cached items from other test runs
        cache.clear()
        response = c.get(reverse('firedepartment_detail', args=[fd.pk]))
        prefix = hash_for_cache('firestation.change_firedepartment', '/departments/86610')
        keys = cache._cache.keys()
        self.assertTrue(any([prefix in x for x in keys]))

        # prime the cache with a slugged page path that is very long
        response = c.get(reverse('firedepartment_detail_slug', args=[fd.pk, fd.slug]))
        c.logout()

        # tester_mcgee doesn't have firestation.change_firedepartment permissions, so *should* have an empty PERMS qualifier
        c.login(**{'username': '******', 'password': '******'})
        response = c.get(reverse('firedepartment_detail', args=[fd.pk]))
        keys = cache._cache.keys()
        prefix = hash_for_cache(None, '/departments/86610')
        self.assertTrue(any([prefix in x for x in keys]))

        # ensure that NONE of the keys blow out the max memcached key length
        self.assertFalse(any([len(k) > 250 for k in keys]))
コード例 #2
0
def create_quartile_views_task():
    """
    Updates the Quartile Materialized Views.
    """
    return create_quartile_views(None)