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())
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())
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_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 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)
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)
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())