Exemplo n.º 1
0
    def test_customstyles_are_stored_in_btree(self):
        adapter = ICustomStyles(self.portal)
        adapter.set('css.body-background', 'blue')

        annotations = IAnnotations(self.portal)
        self.assertEquals(OOBTree,
                          type(annotations.get(CUSTOMSTYLES_ANNOTATION_KEY)))
class TestCustomStyling(unittest.TestCase):

    layer = PUBLISHER_CORE_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        login(self.portal, TEST_USER_NAME)

        if ONEGOV_THEME_INSTALLED:
            from plonetheme.onegov.interfaces import ICustomStyles
            self.custom = ICustomStyles(self.portal)
            self.input_ = {'css.body-background': 'red'}
            self.custom.set_styles(self.input_)

    @unittest.skipUnless(ONEGOV_THEME_INSTALLED,
                          'plonetheme.onegov not installed')
    def test_custom_style_getter(self):
        component = getAdapter(self.portal, IDataCollector,
                               name='custom_style_adapter')

        data = component.getData()
        self.assertEquals(self.input_, data)

    @unittest.skipUnless(ONEGOV_THEME_INSTALLED,
                          'plonetheme.onegov not installed')
    def test_custom_style_setter(self):
        self.custom.set_styles({})
        component = getAdapter(self.portal, IDataCollector,
                               name='custom_style_adapter')
        self.assertEquals({}, component.getData())

        component.setData(self.input_, {})

        self.assertEquals(self.input_, component.getData())
class TestCustomStyling(unittest2.TestCase):

    layer = PUBLISHER_CORE_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        login(self.portal, TEST_USER_NAME)

        if ONEGOV_THEME_INSTALLED:
            from plonetheme.onegov.interfaces import ICustomStyles
            self.custom = ICustomStyles(self.portal)
            self.input_ = {'css.body-background': 'red'}
            self.custom.set_styles(self.input_)

    @unittest2.skipUnless(ONEGOV_THEME_INSTALLED,
                          'plonetheme.onegov not installed')
    def test_custom_style_getter(self):
        component = getAdapter(self.portal, IDataCollector,
                               name='custom_style_adapter')

        data = component.getData()
        self.assertEquals(self.input_, data)

    @unittest2.skipUnless(ONEGOV_THEME_INSTALLED,
                          'plonetheme.onegov not installed')
    def test_custom_style_setter(self):
        self.custom.set_styles({})
        component = getAdapter(self.portal, IDataCollector,
                               name='custom_style_adapter')
        self.assertEquals({}, component.getData())

        component.setData(self.input_, {})

        self.assertEquals(self.input_, component.getData())
    def test_caches_are_invalidated_when_resetting_EXISTING_values(self):
        adapter = ICustomStyles(self.portal)
        adapter.set('css.body-background', 'red')

        invalidate_cache_mock = self.mocker.replace(
            'plonetheme.onegov.browser.customstyles.invalidate_cache')
        self.expect(invalidate_cache_mock())
        self.replay()

        adapter.set('css.body-background', 'blue')
    def test_caches_are_invalidated_when_setting_NEW_values(self):
        adapter = ICustomStyles(self.portal)
        self.assertEquals({}, adapter.get_styles())

        invalidate_cache_mock = self.mocker.replace(
            'plonetheme.onegov.browser.customstyles.invalidate_cache')
        self.expect(invalidate_cache_mock())
        self.replay()

        adapter.set('css.body-background', 'blue')
Exemplo n.º 6
0
    def test_caches_are_invalidated_when_setting_NEW_values(self):
        adapter = ICustomStyles(self.portal)
        self.assertEquals({}, adapter.get_styles())

        invalidate_cache_mock = self.mocker.replace(
            'plonetheme.onegov.browser.customstyles.invalidate_cache')
        self.expect(invalidate_cache_mock())
        self.replay()

        adapter.set('css.body-background', 'blue')
    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        login(self.portal, TEST_USER_NAME)

        if ONEGOV_THEME_INSTALLED:
            from plonetheme.onegov.interfaces import ICustomStyles
            self.custom = ICustomStyles(self.portal)
            self.input_ = {'css.body-background': 'red'}
            self.custom.set_styles(self.input_)
Exemplo n.º 8
0
 def get_options(self):
     nav_root = self.context.restrictedTraverse(
         getNavigationRoot(self.context))
     options = ICustomStyles(nav_root).get_styles()
     styles = []
     for key, value in options.items():
         if value and key.startswith('css.'):
             styles.append('$%s: %s;' % (key.replace('css.', ''), value))
         if value and key == 'custom_scss':
             styles.append(value)
     return '\n'.join(styles)
Exemplo n.º 9
0
 def get_options(self):
     nav_root = self.context.restrictedTraverse(
         getNavigationRoot(self.context))
     options = ICustomStyles(nav_root).get_styles()
     styles = []
     for key, value in options.items():
         if value and key.startswith('css.'):
             styles.append('$%s: %s;' % (key.replace('css.', ''),
                                         value))
         if value and key == 'custom_scss':
             styles.append(value)
     return '\n'.join(styles)
    def test_mutating_styles_directly_does_not_store_them(self):
        adapter = ICustomStyles(self.portal)

        input = {'css.body-background': 'red'}
        adapter.set_styles(input)

        output = adapter.get_styles()
        self.assertEquals(input, output)

        output['css.body-background'] = 'green'
        self.assertEquals(input, adapter.get_styles(),
                          'The result of get_styles could be modified so that'
                          ' it changed in the storage, which should not happen.')
Exemplo n.º 11
0
    def save_values(self, items):
        def include(item):
            name, _value = item
            if name.startswith('css.'):
                return True
            if name.startswith('img.'):
                return True
            if name == 'custom_scss':
                return True
            return False

        styles = dict(filter(include, items.items()))
        adapter = ICustomStyles(self.context)
        styles[TIMESTAMP_ANNOTATION_KEY] = str(time.time()).replace('.', '')
        adapter.set_styles(styles)
Exemplo n.º 12
0
    def save_values(self, items):
        def include(item):
            name, _value = item
            if name.startswith('css.'):
                return True
            if name.startswith('img.'):
                return True
            if name == 'custom_scss':
                return True
            return False

        styles = dict(filter(include, items.items()))
        adapter = ICustomStyles(self.context)
        styles[TIMESTAMP_ANNOTATION_KEY] = str(time.time()).replace('.','')
        adapter.set_styles(styles)
Exemplo n.º 13
0
def importCustomstyles(import_context):
    """Import custom styles defined as a json file named "customstyles.json"
    within any generic setup directory.

    The file contains the exportable JSON and may be extended with a "path" key
    containing the relative path to the target object where the custom styles
    should be set on. When there is no "path", the styles are set on the site
    root.
    """

    files = import_context.listDirectory('.') or []
    filenames = filter(FILENAME_PATTERN.match, files)

    for filename in filenames:
        filedata = import_context.readDataFile(filename)
        if filedata is None:
            continue

        styles = json.loads(filedata)
        site = import_context.getSite()
        if 'path' in styles:
            context = site.restrictedTraverse(styles['path'].encode('utf-8'))
            del styles['path']
        else:
            context = site

        ICustomStyles(context).set_styles(styles)
Exemplo n.º 14
0
 def test_favicon_config(self, browser):
     ICustomStyles(self.portal).set('img.favicon', '%PORTAL_URL%/my-fav.ico')
     transaction.commit()
     browser.open()
     tag = browser.css('link[type="image/x-icon"]').first
     self.assertEquals('http://nohost/plone/my-fav.ico',
                       tag.attrib.get('href'))
    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?')
Exemplo n.º 16
0
 def test_startup_image_config(self, browser):
     ICustomStyles(self.portal).set('img.startup', '%PORTAL_URL%/s.png')
     transaction.commit()
     browser.open()
     tag = browser.css('link[rel="apple-touch-startup-image"]').first
     self.assertEquals('http://nohost/plone/s.png',
                       tag.attrib.get('href'))
Exemplo n.º 17
0
 def test_touch_iphone_config(self, browser):
     ICustomStyles(self.portal).set('img.touch_iphone', '%PORTAL_URL%/t.png')
     transaction.commit()
     browser.open()
     tag = browser.css('link[rel="apple-touch-icon"]').first
     self.assertEquals('http://nohost/plone/t.png',
                       tag.attrib.get('href'))
Exemplo n.º 18
0
def exportCustomstyles(export_context):
    """Export custom styles defined on the site root.
    """

    site = export_context.getSite()
    styles = ICustomStyles(site).get_styles()
    data = json.dumps(styles, sort_keys=True, indent=4)
    export_context.writeDataFile('customstyles.json', data, 'application/json')
    def setUp(self):
        self.portal = self.layer['portal']
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        login(self.portal, TEST_USER_NAME)

        if ONEGOV_THEME_INSTALLED:
            from plonetheme.onegov.interfaces import ICustomStyles
            self.custom = ICustomStyles(self.portal)
            self.input_ = {'css.body-background': 'red'}
            self.custom.set_styles(self.input_)
Exemplo n.º 20
0
    def update(self):
        super(MetaViewlet, self).update()
        navroot = self.context.restrictedTraverse(
            getNavigationRoot(self.context))
        self.customstyles = ICustomStyles(navroot).get_styles()

        self.favicon = self.customstyle_value('img.favicon') or \
            '/'.join((navroot.absolute_url(), 'favicon.ico'))
        self.startup = self.customstyle_value('img.startup')
        self.touch_iphone = self.customstyle_value('img.touch_iphone')
        self.touch_iphone_76 = self.customstyle_value('img.touch_iphone_76')
        self.touch_iphone_120 = self.customstyle_value('img.touch_iphone_120')
        self.touch_iphone_152 = self.customstyle_value('img.touch_iphone_152')
Exemplo n.º 21
0
    def export_styles(self, download=False):
        """Returns a json file containing the styles.
        """
        if download:
            normalizer = getUtility(IIDNormalizer)
            normalized_title = normalizer.normalize(self.context.Title())
            self.context.REQUEST.RESPONSE.setHeader(
                'Content-Type', 'text/json; charset=utf-8')
            self.context.REQUEST.RESPONSE.setHeader(
                'Content-disposition',
                'attachment; filename=customstyles_%s.json' % normalized_title)

        return json.dumps(ICustomStyles(self.context).get_styles())
Exemplo n.º 22
0
    def test_caches_are_invalidated_when_resetting_EXISTING_values(self):
        adapter = ICustomStyles(self.portal)
        adapter.set('css.body-background', 'red')

        invalidate_cache_mock = self.mocker.replace(
            'plonetheme.onegov.browser.customstyles.invalidate_cache')
        self.expect(invalidate_cache_mock())
        self.replay()

        adapter.set('css.body-background', 'blue')
Exemplo n.º 23
0
    def test_mutating_styles_directly_does_not_store_them(self):
        adapter = ICustomStyles(self.portal)

        input = {'css.body-background': 'red'}
        adapter.set_styles(input)

        output = adapter.get_styles()
        self.assertEquals(input, output)

        output['css.body-background'] = 'green'
        self.assertEquals(
            input, adapter.get_styles(),
            'The result of get_styles could be modified so that'
            ' it changed in the storage, which should not happen.')
    def test_customstyles_are_stored_in_btree(self):
        adapter = ICustomStyles(self.portal)
        adapter.set('css.body-background', 'blue')

        annotations = IAnnotations(self.portal)
        self.assertEquals(OOBTree, type(annotations.get(CUSTOMSTYLES_ANNOTATION_KEY)))
    def test_setting_and_getting_single_style(self):
        adapter = ICustomStyles(self.portal)

        adapter.set('css.body-background', 'blue')
        self.assertEquals('blue', adapter.get('css.body-background'))
 def get_style(self, style, of=None):
     context = of or self.layer['portal']
     return ICustomStyles(context).get(style)
    def test_setting_and_getting_styles(self):
        adapter = ICustomStyles(self.portal)

        styles = {'css.body-background': 'red'}
        adapter.set_styles(styles)
        self.assertEquals(styles, adapter.get_styles())
 def test_implements_interface(self):
     self.assertTrue(ICustomStyles.implementedBy(CustomStyles))
     verifyClass(ICustomStyles, CustomStyles)
Exemplo n.º 29
0
 def test_implements_interface(self):
     self.assertTrue(ICustomStyles.implementedBy(CustomStyles))
     verifyClass(ICustomStyles, CustomStyles)
Exemplo n.º 30
0
    def test_setting_and_getting_styles(self):
        adapter = ICustomStyles(self.portal)

        styles = {'css.body-background': 'red'}
        adapter.set_styles(styles)
        self.assertEquals(styles, adapter.get_styles())
Exemplo n.º 31
0
    def test_setting_and_getting_single_style(self):
        adapter = ICustomStyles(self.portal)

        adapter.set('css.body-background', 'blue')
        self.assertEquals('blue', adapter.get('css.body-background'))
Exemplo n.º 32
0
 def getData(self):
     return ICustomStyles(self.obj).get_styles()
def link_color_in(context):
    return ICustomStyles(context).get('css.link-color')
Exemplo n.º 34
0
 def setData(self, themedata, metadata):
     ICustomStyles(self.obj).set_styles(themedata)
Exemplo n.º 35
0
 def test_new_timestamp_after_save_styles(self):
     timestamp = 'a random timestamp'
     ICustomStyles(self.portal).set(TIMESTAMP_ANNOTATION_KEY, timestamp)
     CustomStylesForm(self.portal, self.request).save_values({})
     self.assertNotEquals(timestamp,
                          self.get_viewlet(self.portal).timestamp())
Exemplo n.º 36
0
 def options(self):
     return ICustomStyles(self.context).get_styles()
Exemplo n.º 37
0
 def timestamp(self):
     nav_root = self.context.restrictedTraverse(
         getNavigationRoot(self.context))
     return ICustomStyles(nav_root).get(TIMESTAMP_ANNOTATION_KEY, '')
Exemplo n.º 38
0
 def test_timestamp_from_annotations(self):
     timestamp = 'a random timestamp'
     ICustomStyles(self.portal).set(TIMESTAMP_ANNOTATION_KEY, timestamp)
     self.assertEquals(timestamp, self.get_viewlet(self.portal).timestamp())