Esempio n. 1
0
 def testImageSizesWithoutPIL(self):
     hasPIL = utils.hasPIL
     utils.hasPIL = False
     self.assertEqual(getImageSize(getFile('image.gif')), (200, 200))
     self.assertEqual(getImageSize(getFile('image.png')), (500, 200))
     # the fallback method cannot handle jpegs properly
     self.assertEqual(getImageSize(getFile('image.jpg')), (-1, -1))
     utils.hasPIL = hasPIL
Esempio n. 2
0
 def testImageSizesWithoutPIL(self):
     hasPIL = utils.hasPIL
     utils.hasPIL = False
     self.assertEqual(getImageSize(getFile('image.gif')), (200, 200))
     self.assertEqual(getImageSize(getFile('image.png')), (500, 200))
     # the fallback method cannot handle jpegs properly
     self.assertEqual(getImageSize(getFile('image.jpg')), (-1, -1))
     utils.hasPIL = hasPIL
Esempio n. 3
0
 def testBlobbableOFSFileWithoutFileName(self):
     obj = File('foo', 'Foo', getFile('plone.pdf'), 'application/pdf')
     blobbable = IBlobbable(obj)
     target = Blob()
     blobbable.feed(target)
     self.assertEqual(target.open('r').read(), getFile('plone.pdf').read())
     self.assertEqual(blobbable.filename(), '')
     self.assertEqual(blobbable.mimetype(), 'application/pdf')
Esempio n. 4
0
 def testBlobbableOFSFileWithoutFileName(self):
     obj = File('foo', 'Foo', getFile('plone.pdf'), 'application/pdf')
     blobbable = IBlobbable(obj)
     target = Blob()
     blobbable.feed(target)
     self.assertEqual(target.open('r').read(),
         getFile('plone.pdf').read())
     self.assertEqual(blobbable.filename(), '')
     self.assertEqual(blobbable.mimetype(), 'application/pdf')
Esempio n. 5
0
 def testGetSize(self):
     item = self.create(foo=getFile('test.pdf'), bar=getFile('image.jpg'))
     field = item.getField('foo')
     self.assertRaises(AttributeError, getattr, field, 'getSize')
     field = item.getField('bar')
     self.assertEqual(field.getSize(item), (500, 200))
     # empty images should return (0, 0)
     field = item.getField('hmm')
     self.assertEqual(field.getSize(item), (0, 0))
Esempio n. 6
0
 def testGetSize(self):
     item = self.create(foo=getFile('test.pdf'), bar=getFile('image.jpg'))
     field = item.getField('foo')
     self.assertRaises(AttributeError, getattr, field, 'getSize')
     field = item.getField('bar')
     self.assertEqual(field.getSize(item), (500, 200))
     # empty images should return (0, 0)
     field = item.getField('hmm')
     self.assertEqual(field.getSize(item), (0, 0))
Esempio n. 7
0
 def testGetSize(self):
     item = self.create(foo=getFile("test.pdf"), bar=getFile("image.jpg"))
     field = item.getField("foo")
     self.assertRaises(AttributeError, getattr, field, "getSize")
     field = item.getField("bar")
     self.assertEqual(field.getSize(item), (500, 200))
     # empty images should return (0, 0)
     field = item.getField("hmm")
     self.assertEqual(field.getSize(item), (0, 0))
Esempio n. 8
0
 def testStringDataRespectsFilename(self):
     item = self.create()
     file_ = getFile('test.pdf')
     item.setFoo(file_.read(), filename='file.xls', mimetype=None)
     self.assertEqual(
         'application/vnd.ms-excel',
         item.getFoo().getContentType(),
     )
Esempio n. 9
0
 def testStringDataRespectsFilename(self):
     item = self.create()
     file_ = getFile('test.pdf')
     item.setFoo(file_.read(), filename='file.xls', mimetype=None)
     self.assertEqual(
         'application/vnd.ms-excel',
         item.getFoo().getContentType()
         )
Esempio n. 10
0
 def testBlobbableBinaryFile(self):
     _file = os.path.join(os.path.dirname(__file__), 'data', 'image.gif')
     with open(_file, 'rb') as f:
         obj = Binary(f)
         obj.filename = 'image.gif'
         blobbable = IBlobbable(obj)
         target = Blob()
         blobbable.feed(target)
         self.assertEqual(target.open('r').read(),
                          getFile('image.gif').read())
         self.assertEquals(blobbable.filename(), 'image.gif')
         self.assertEquals(blobbable.mimetype(), 'image/gif')
Esempio n. 11
0
 def testBlobbableBinaryFile(self):
     _file = os.path.join(os.path.dirname(__file__), 'data', 'image.gif')
     with open(_file, 'rb') as f:
         obj = Binary(f)
         obj.filename = 'image.gif'
         blobbable = IBlobbable(obj)
         target = Blob()
         blobbable.feed(target)
         self.assertEqual(
             target.open('r').read(),
             getFile('image.gif').read())
         self.assertEquals(blobbable.filename(), 'image.gif')
         self.assertEquals(blobbable.mimetype(), 'image/gif')
Esempio n. 12
0
    def test_uploadFile(self):
        file = File('foo', 'Foo', getFile('plone.pdf'), 'application/pdf')
        file.filename = 'foo.pdf'

        myUpload = makeFileUpload(file, 'test.gif')
        myUpload.method = 'GET'
        view = VNCCollabUtilView(self.portal, myUpload)
        self.assertRaises(Exception, lambda:  view.uploadFile(myUpload))

        myUpload = makeFileUpload(file, 'test.gif')
        myUpload.method = 'POST'
        myUpload.form = {}
        headers, output, request = makeResponse(myUpload)
        view = VNCCollabUtilView(self.portal, request)
        result = view.uploadFile(file)
        self.assertEqual(result, 'http://nohost/plone/foo.pdf/edit')

        myUpload = makeFileUpload(file, 'test.gif')
        myUpload.method = 'POST'
        myUpload.form = {'ajax_call': True}
        headers, output, request = makeResponse(myUpload)
        view = VNCCollabUtilView(self.portal, request)
        result = view.uploadFile(file)
        self.assertEqual(result, 'http://nohost/plone/foo.pdf-1/edit')
Esempio n. 13
0
 def testImageField(self):
     foo = self.create(bar=getFile("image.jpg"))
     self.assertEqual(str(foo.getBar()), getFile("image.jpg").read())
     self.assertTrue(foo.getField("bar").tag(foo).startswith("<img src"))
Esempio n. 14
0
 def testFileField(self):
     foo = self.create(foo=getFile('test.pdf'))
     self.assertEqual(str(foo.getFoo()), getFile('test.pdf').read())
Esempio n. 15
0
 def testImageSizes(self):
     self.assertEqual(getImageSize(getFile('image.gif')), (200, 200))
     self.assertEqual(getImageSize(getFile('image.png')), (500, 200))
     self.assertEqual(getImageSize(getFile('image.jpg')), (500, 200))
Esempio n. 16
0
 def testImageField(self):
     foo = self.create(bar=getFile('image.jpg'))
     self.assertEqual(str(foo.getBar()), getFile('image.jpg').read())
     self.assertTrue(foo.getField('bar').tag(foo).startswith('<img src'))
Esempio n. 17
0
 def testSetFieldDefaultMime(self):
     item = self.create()
     file_ = getFile('test.pdf')
     item.setFoo(file_, filename='file.blubb', mimetype=None)
     self.assertEqual('application/pdf', item.getFoo().getContentType())
Esempio n. 18
0
 def testSetFieldDefaultMime(self):
     item = self.create()
     file_ = getFile('test.pdf')
     item.setFoo(file_, filename='file.blubb', mimetype=None)
     self.assertEqual('application/pdf', item.getFoo().getContentType())
Esempio n. 19
0
 def testImageSizes(self):
     self.assertEqual(getImageSize(getFile('image.gif')), (200, 200))
     self.assertEqual(getImageSize(getFile('image.png')), (500, 200))
     self.assertEqual(getImageSize(getFile('image.jpg')), (500, 200))
Esempio n. 20
0
 def testImageField(self):
     foo = self.create(bar=getFile('image.jpg'))
     self.assertEqual(str(foo.getBar()), getFile('image.jpg').read())
     self.assertTrue(foo.getField('bar').tag(foo).startswith('<img src'))
Esempio n. 21
0
 def testFileField(self):
     foo = self.create(foo=getFile('test.pdf'))
     self.assertEqual(str(foo.getFoo()), getFile('test.pdf').read())