예제 #1
0
    def test_get_cachkey_only_with_dynamic_resources(self):
        """In production we only respect cachekeys of dynamic resources in order
        to speed up cachekey calculation and because everything else should be
        static. We also do not want to change cache keys in production too often.

        Therefore the compiler's get_cachekey method has a dynamic_resources_only
        param.
        """
        resource = DynamicSCSSResource('foo', cachekey='foo')
        getUtility(ISCSSRegistry).add_resource(resource)

        compiler = getMultiAdapter((self.portal, self.request), ISCSSCompiler)
        initial_cachekey = compiler.get_cachekey(dynamic_resources_only=True)
        self.assertEqual(initial_cachekey,
                         compiler.get_cachekey(dynamic_resources_only=True))
        resource.cachekey = 'bar'
        self.assertNotEqual(initial_cachekey,
                            compiler.get_cachekey(dynamic_resources_only=True))
    def test_cachekey_changes_when_dynamic_resource_cachekey_changes(self, browser):
        resource = DynamicSCSSResource('foo', cachekey='foo')
        getUtility(ISCSSRegistry).add_resource(resource)

        self._set_debug_mode(False)
        browser.open()
        theming_css_url = self.get_css_url('http://nohost/plone/theming.css')
        self.assertIn('?cachekey=', theming_css_url, 'Missing cachekey param.')

        browser.reload()
        self.assertEqual(theming_css_url,
                         self.get_css_url('http://nohost/plone/theming.css'),
                         'URL (cachekey?) did unexpectedly change.')

        resource.cachekey = 'bar'

        browser.reload()
        self.assertNotEqual(theming_css_url,
                            self.get_css_url('http://nohost/plone/theming.css'),
                            'Cachekey should have changed.')
예제 #3
0
 def test_get_cachekey_can_be_passed_on_initialization(self):
     resource = DynamicSCSSResource("foo", cachekey="bar")
     self.assertEquals("bar", resource.get_cachekey(None, None))
예제 #4
0
 def test_get_cachekey_must_be_implemented(self):
     resource = DynamicSCSSResource("foo")
     with self.assertRaises(NotImplementedError):
         resource.get_cachekey(None, None)