def test_ImageContentTypeUponConstruction(self): # Test the content type after calling the constructor with the # file object being passed in (http://www.zope.org/Collectors/CMF/370) testfile = open(TEST_JPG, 'rb') image = Image('testimage', file=testfile) testfile.close() self.assertEqual(image.Format(), 'image/jpeg') self.assertEqual(image.content_type, 'image/jpeg')
def test_Image_setFormat(self): # Setting the DC.format must also set the content_type property image = Image('testimage', format='image/jpeg') self.assertEqual(image.Format(), 'image/jpeg') self.assertEqual(image.content_type, 'image/jpeg') image.setFormat('image/gif') self.assertEqual(image.Format(), 'image/gif') self.assertEqual(image.content_type, 'image/gif')
def test_getId_on_old_Image_instance(self): image = self.site._setObject('testimage', Image('testimage')) self.assertEqual(image.getId(), 'testimage') self.assertEqual(image.id, 'testimage') # Mimick old instance when base classes had OFS.Image.Image first image.__name__ = 'testimage' delattr(image, 'id') self.assertEqual(image.getId(), 'testimage') self.assertEqual(image.id(), 'testimage')
def test_Image_setFormat(self): # Setting the format must also set the content_type property image = Image('testimage', format='image/jpeg') self.assertEqual(image.Format(), 'image/jpeg') self.assertEqual(image.content_type, 'image/jpeg') image.setFormat('image/gif') self.assertEqual(image.Format(), 'image/gif') self.assertEqual(image.content_type, 'image/gif')
def test_EditWithEmptyFile(self): # Test handling of empty file uploads image = Image('testimage') testfile = open(TEST_JPG, 'rb') image.edit(file=testfile) testfile.seek(0, 2) testfilesize = testfile.tell() testfile.close() assert image.get_size() == testfilesize emptyfile = cStringIO.StringIO() image.edit(file=emptyfile) assert image.get_size() > 0 assert image.get_size() == testfilesize
def test_EditWithEmptyFile(self): """ Test handling of empty file uploads """ image = Image('testimage') testfile = open(TEST_JPG, 'rb') image.edit(file=testfile) testfile.seek(0,2) testfilesize = testfile.tell() testfile.close() assert image.get_size() == testfilesize emptyfile = cStringIO.StringIO() image.edit(file=emptyfile) assert image.get_size() > 0 assert image.get_size() == testfilesize