Ejemplo n.º 1
0
    def test_get_placeholder_cache_key(self):
        version, vary_on_list = _get_placeholder_cache_version(self.placeholder, 'en', 1)
        desired_key = '{prefix}|render_placeholder|id:{id}|lang:{lang}|site:{site}|tz:{tz}|v:{version}|country-code:{cc}'.format(  # noqa
            prefix=get_cms_setting('CACHE_PREFIX'),
            id=self.placeholder.pk,
            lang='en',
            site=1,
            tz=get_timezone_name(),
            version=version,
            cc='_',
        )
        _set_placeholder_cache_version(self.placeholder, 'en', 1, version, vary_on_list=vary_on_list, duration=1)
        actual_key = _get_placeholder_cache_key(self.placeholder, 'en', 1, self.en_request)
        self.assertEqual(actual_key, desired_key)

        en_key = _get_placeholder_cache_key(self.placeholder, 'en', 1, self.en_request)
        de_key = _get_placeholder_cache_key(self.placeholder, 'de', 1, self.de_request)
        self.assertNotEqual(en_key, de_key)

        en_us_key = _get_placeholder_cache_key(self.placeholder, 'en', 1, self.en_us_request)
        self.assertNotEqual(en_key, en_us_key)

        desired_key = '{prefix}|render_placeholder|id:{id}|lang:{lang}|site:{site}|tz:{tz}|v:{version}|country-code:{cc}'.format(  # noqa
            prefix=get_cms_setting('CACHE_PREFIX'),
            id=self.placeholder.pk,
            lang='en',
            site=1,
            tz=get_timezone_name(),
            version=version,
            cc='US',
        )
        self.assertEqual(en_us_key, desired_key)
Ejemplo n.º 2
0
 def test_set_clear_get_placeholder_cache_version(self):
     initial, _ = _get_placeholder_cache_version(self.placeholder, 'en', 1)
     clear_placeholder_cache(self.placeholder, 'en', 1)
     version, _ = _get_placeholder_cache_version(self.placeholder, 'en', 1)
     self.assertGreater(version, initial)