Пример #1
0
Файл: mdb.py Проект: louika/vivi
 def get_body(self, mdb_id):
     response = self._request('GET /mdb/%s/file' % mdb_id)
     response = response.text
     # Yep, they're sending megabytes of data in an XML envelope; let's not
     # put that through an XML parser without a really good reason.
     body = XML_TAGS.sub('', response)
     body = base64.b64decode(body)
     # Cannot use cStringIO since we need to set additional attributes.
     result = StringIO(body)
     result.filename = FILE_NAME_ATTRIBUTE.search(response).group(1)
     result.mdb_id = mdb_id
     result.headers = {'content-type': 'image/%s' % os.path.splitext(
         result.filename)[1].lower()}
     return result
Пример #2
0
 def testWebDavUpdate(self):
     image = StringIO(getImage())
     image.filename = 'original.gif'
     base = '/'.join(self.folder.getPhysicalPath())
     response = self.publish(base + '/foo-image', request_method='PUT',
                             stdin=image, basic=self.getCredentials(),
                             env={'CONTENT_TYPE': 'image/gif'})
     self.assertEqual(response.getStatus(), 204)
     self.assertTrue('foo-image' in self.folder.objectIds())
     fooimage = self.folder['foo-image']
     self.assertEqual(fooimage.getId(), 'foo-image')
     self.assertEqual(fooimage.Title(), 'an image')
     # as opposed to during file upload, editing a file via webdav (e.g.
     # using the "external editor" feature) should not change the filename
     self.assertEqual(fooimage.getFilename(), 'original.gif')
Пример #3
0
 def testWebDavUpload(self):
     image = StringIO(getImage())
     image.filename = 'original.gif'
     base = '/'.join(self.folder.getPhysicalPath())
     response = self.publish(base + '/image', request_method='PUT',
                             stdin=image, basic=self.getCredentials(),
                             env={'CONTENT_TYPE': 'image/gif'})
     self.assertEqual(response.getStatus(), 201)
     self.assertTrue('image' in self.folder.objectIds())
     obj = self.folder.image
     self.assertEqual(obj.getPortalTypeName(), 'Image')
     self.assertTrue(IATBlobImage.providedBy(obj), 'no blob?')
     self.assertEqual(str(obj.getField('image').get(obj)), image.getvalue())
     # on initial (webdav) upload no filename is set by the client,
     # so it should end up being equal to the last path/url component...
     self.assertEqual(obj.getFilename(), 'image')
Пример #4
0
    def setUpPloneSite(self, portal):
        for name in ['file', 'image']:
            self.applyProfile(
                portal,
                'plone.app.blob:{0}-replacement'.format(name),
            )
        # allow creating the replaced types
        types = getToolByName(portal, 'portal_types')
        assert types.getTypeInfo('Blob').product == 'plone.app.blob'
        types.getTypeInfo('ATFile').global_allow = True
        types.getTypeInfo('ATImage').global_allow = True

        testing.setRoles(portal, testing.TEST_USER_ID, ['Manager'])
        folder = portal.portal_membership.getHomeFolder(testing.TEST_USER_ID)

        image = StringIO(getData('image.gif'))
        image.filename = 'original.gif'
        folder.invokeFactory('Image',
                             id='foo-image',
                             title='an image',
                             image=image)
Пример #5
0
 def test_filename(self):
     content = StringIO('test')
     content.filename = 'test.txt'
     b = Blob(content)
     assert 'filename' in b.meta
     assert b.meta['filename'] == 'test.txt'
Пример #6
0
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import ploneSite
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.app.testing import TEST_USER_PASSWORD
from plone.namedfile.file import NamedImage
from plone.testing import z2
from Products.Archetypes.interfaces import IBaseObject
from Products.CMFCore.utils import getToolByName
from six import StringIO
from zope.configuration import xmlconfig

B64_DATA = 'R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='
GIF = StringIO(decodestring(B64_DATA))
GIF.filename = 'sample.gif'
GIF.contentType = 'image/gif'
GIF._width = 1
GIF._height = 1


def create(container, type_name, **kwargs):
    """A easy helper method to create some content since we do not have
    plone.api in core.
    """

    new_id = container.invokeFactory(type_name, **kwargs)
    content = container[new_id]

    # Archetypes specific code was taken from ``plone.api``
    # Switch when api has been merged into core.