Пример #1
0
 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)
Пример #3
0
 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)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
def get_file_b64encoded(filename):
    """Load file from current directory and return it b64encoded."""
    data = get_file(filename)
    return b64encode_file(filename, data)
Пример #7
0
def encode_image(image):
    """Return image encoded in base64"""
    return b64encode_file(image, load_file(image))
Пример #8
0
 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)
Пример #9
0
 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)