def test_get_site_icon(self): registry = getUtility(IRegistry) registry['plone.site_icon'] = b64encode_file('foobar.gif', bimage) view = IconView(self.portal, self.request) self.request.form.update({'scale': '180'}) result = view._getFile() self.assertTrue(INamedFile.providedBy(result))
def get_encoded_image(filename): """Return image encoded in base64.""" cwd = os.path.abspath(os.path.dirname(__file__)) path = os.path.join(cwd, 'tests', filename) with open(path, 'rb') as f: data = f.read() return b64encode_file(filename, data)
def setUp(self): self.portal = self.layer['portal'] self.request = self.layer['request'] login(self.portal, TEST_USER_NAME) setRoles(self.portal, TEST_USER_ID, ('Member', 'Manager')) registry = getUtility(IRegistry) registry['plone.site_icon'] = b64encode_file('foobar.gif', bimage) self.view = IconView(self.portal, self.request)
def logo(context, remove=False): registry = getUtility(IRegistry) settings = registry.forInterface(ISiteSchema, prefix="plone", check=False) filename = 'logo.png' b64 = b64encode_file(filename, get_file(filename)) if hasattr(settings, 'site_logo'): if remove: setattr(settings, 'site_logo', '') else: setattr(settings, 'site_logo', b64)
def get_file_b64encoded(filename): """Load file from current directory and return it b64encoded.""" from plone.formwidget.namedfile.converter import b64encode_file data = get_file(filename) return b64encode_file(filename, data)
def get_file_b64encoded(filename): """Load file from current directory and return it b64encoded.""" data = get_file(filename) return b64encode_file(filename, data)
def encode_image(image): """Return image encoded in base64""" return b64encode_file(image, load_file(image))
def test_get_site_icon_raises_404(self): registry = getUtility(IRegistry) registry['plone.site_icon'] = b64encode_file('foobar.gif', bimage) view = IconView(self.portal, self.request) self.request.form.update({'scale': '555'}) self.assertRaises(NotFound, view._getFile)
def test_get_site_icon_does_not_raise_overflow_error(self): registry = getUtility(IRegistry) registry['plone.site_icon'] = b64encode_file('foobar.gif', bimage) view = IconView(self.portal, self.request) self.request.form.update({'scale': '-3284239847329'}) self.assertRaises(NotFound, view._getFile)