def test_File_setFormat(self): # Setting the format must also set the content_type property file = File('testfile', format='image/jpeg') self.assertEqual(file.Format(), 'image/jpeg') self.assertEqual(file.content_type, 'image/jpeg') file.setFormat('image/gif') self.assertEqual(file.Format(), 'image/gif') self.assertEqual(file.content_type, 'image/gif')
def test_getId_on_old_File_instance(self): file = self.site._setObject('testfile', File('testfile')) self.assertEqual(file.getId(), 'testfile') self.assertEqual(file.id, 'testfile') # Mimick old instance when base classes had OFS.Image.File first file.__name__ = 'testfile' delattr(file, 'id') self.assertEqual(file.getId(), 'testfile') self.assertEqual(file.id(), 'testfile')
def test_FileContentTypeUponConstruction(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') # Notice the cheat? File objects lack the extra intelligence that # picks content types from the actual file data, so it needs to be # helped along with a file extension... file = File('testfile.jpg', file=testfile) testfile.close() self.assertEqual(file.Format(), 'image/jpeg') self.assertEqual(file.content_type, 'image/jpeg')