def test_result_is_cached(self):
        view = self.get_view()
        self.assertNotIn('purple', view.generate_css(),
                         'Unexpectedly found "purple" in the CSS')

        # Setting a custom style automatically invalidates the cache.
        # For testing that things are cached, we stub the cache invalidation,
        # so that the cache persists.
        mocker = Mocker()
        invalidate_cache_mock = mocker.replace(invalidate_cache)
        expect(invalidate_cache_mock()).count(1, None)
        mocker.replay()

        ICustomStyles(self.layer['portal']).set('css.body-background',
                                                'purple')
        self.assertNotIn('purple', view.generate_css(),
                         'The result was not cached.')

        # Removing the stub and invalidating the cache should update the result.
        mocker.restore()
        mocker.verify()
        invalidate_cache()
        self.assertIn(
            'purple', view.generate_css(),
            'Expected "purple" in CSS - does the style'
            ' css.body-background no longer work?')
    def test_result_is_cached(self):
        view = self.get_view()
        self.assertNotIn('purple', view.generate_css(),
                         'Unexpectedly found "purple" in the CSS')

        # Setting a custom style automatically invalidates the cache.
        # For testing that things are cached, we stub the cache invalidation,
        # so that the cache persists.
        mocker = Mocker()
        invalidate_cache_mock = mocker.replace(invalidate_cache)
        expect(invalidate_cache_mock()).count(1, None)
        mocker.replay()

        ICustomStyles(self.layer['portal']).set('css.body-background', 'purple')
        self.assertNotIn('purple', view.generate_css(),
                         'The result was not cached.')

        # Removing the stub and invalidating the cache should update the result.
        mocker.restore()
        mocker.verify()
        invalidate_cache()
        self.assertIn('purple', view.generate_css(),
                      'Expected "purple" in CSS - does the style'
                      ' css.body-background no longer work?')
Example #3
0
 def set(self, style, value):
     if not self.annotations.get(CUSTOMSTYLES_ANNOTATION_KEY):
         self.set_styles({style: value})
     else:
         self.annotations[CUSTOMSTYLES_ANNOTATION_KEY][style] = value
         invalidate_cache()
Example #4
0
 def set_styles(self, styles):
     styles = OOBTree(styles)
     self.annotations[CUSTOMSTYLES_ANNOTATION_KEY] = styles
     invalidate_cache()
 def set(self, style, value):
     if not self.annotations.get(CUSTOMSTYLES_ANNOTATION_KEY):
         self.set_styles({style: value})
     else:
         self.annotations[CUSTOMSTYLES_ANNOTATION_KEY][style] = value
         invalidate_cache()
 def set_styles(self, styles):
     styles = OOBTree(styles)
     self.annotations[CUSTOMSTYLES_ANNOTATION_KEY] = styles
     invalidate_cache()