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