예제 #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
예제 #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
예제 #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')
예제 #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')
예제 #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))
예제 #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))
예제 #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))
예제 #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(),
     )
예제 #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()
         )
예제 #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')
예제 #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')
예제 #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')
예제 #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"))
예제 #14
0
 def testFileField(self):
     foo = self.create(foo=getFile('test.pdf'))
     self.assertEqual(str(foo.getFoo()), getFile('test.pdf').read())
예제 #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))
예제 #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'))
예제 #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())
예제 #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())
예제 #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))
예제 #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'))
예제 #21
0
 def testFileField(self):
     foo = self.create(foo=getFile('test.pdf'))
     self.assertEqual(str(foo.getFoo()), getFile('test.pdf').read())