def testCreateScaleWithPdata(self): data = self.getImage() + '\x00' * (1 << 16) from Products.ATContentTypes.content.image import ATImage image = ATImage('image').__of__(self.folder) image.setImage(data) field = image.getField('image') field.swallowResizeExceptions = False from OFS.Image import Pdata self.assertTrue(isinstance(image.getImage().data, Pdata)) adapter = ImageScaling(image, None) foo = adapter.scale('image', width=100, height=80) self.assertFalse(foo is None)
def testQualityChange(self): iprops = self.portal.portal_properties.imaging_properties self.image.update(image=self.getImage('image.jpg')) data = self.getImage('image.jpg') + '\x00' * (1 << 16) # get size of image scaled at default scaling quality self.assertEqual(iprops.getProperty('quality'), 88) from Products.ATContentTypes.content.image import ATImage image = ATImage('image').__of__(self.folder) image.setImage(data) adapter = ImageScaling(image, None) img_high_quality = adapter.scale('image', width=100, height=80) size_high_quality = img_high_quality.size # lower scaling quality and get scaled image's size at that quality iprops.manage_changeProperties(quality=20) self.assertEqual(iprops.getProperty('quality'), 20) image = ATImage('image').__of__(self.folder) image.setImage(data) adapter = ImageScaling(image, None) img_low_quality = adapter.scale('image', width=100, height=80) size_low_quality = img_low_quality.size # data should be smaller at lower quality self.assertTrue(size_high_quality > size_low_quality)
def testQualityChange(self): settings = getSettings() self.image.update(image=self.getImage('image.jpg')) data = self.getImage('image.jpg') + '\x00' * (1 << 16) # get size of image scaled at default scaling quality self.assertEqual(settings.quality, 88) from Products.ATContentTypes.content.image import ATImage image = ATImage('image').__of__(self.folder) image.setImage(data) adapter = ImageScaling(image, None) img_high_quality = adapter.scale('image', width=100, height=80) size_high_quality = img_high_quality.size # lower scaling quality and get scaled image's size at that quality settings.quality = 20 self.assertEqual(settings.quality, 20) image = ATImage('image').__of__(self.folder) image.setImage(data) adapter = ImageScaling(image, None) img_low_quality = adapter.scale('image', width=100, height=80) size_low_quality = img_low_quality.size # data should be smaller at lower quality self.assertTrue(size_high_quality > size_low_quality)
def testCreateScaleWithoutData(self): folder = self.folder image = folder[folder.invokeFactory('Image', id='image')] adapter = ImageScaling(image, None) foo = adapter.scale('image', width=100, height=80) self.assertEqual(foo, None)
class ScalesAdapterTests(ImagingTestCase): def afterSetUp(self): data = self.getImage() folder = self.folder self.image = folder[folder.invokeFactory( 'Image', id='foo', image=data)] self.adapter = ImageScaling(self.image, None) self.iprops = self.portal.portal_properties.imaging_properties self.iprops.manage_changeProperties(allowed_sizes=['foo 60:60']) def testCreateScale(self): foo = self.adapter.scale('image', width=100, height=80) self.assertTrue(foo.uid) self.assertEqual(foo.mimetype, 'image/jpeg') self.assertEqual(foo.width, 80) self.assertEqual(foo.height, 80) self.assertImage(foo.data, 'JPEG', (80, 80)) def testCreateScaleWithoutData(self): folder = self.folder image = folder[folder.invokeFactory('Image', id='image')] adapter = ImageScaling(image, None) foo = adapter.scale('image', width=100, height=80) self.assertEqual(foo, None) def testCreateScaleWithPdata(self): data = self.getImage() + '\x00' * (1 << 16) from Products.ATContentTypes.content.image import ATImage image = ATImage('image').__of__(self.folder) image.setImage(data) field = image.getField('image') field.swallowResizeExceptions = False from OFS.Image import Pdata self.assertTrue(isinstance(image.getImage().data, Pdata)) adapter = ImageScaling(image, None) foo = adapter.scale('image', width=100, height=80) self.assertFalse(foo is None) def testGetScaleByName(self): foo = self.adapter.scale('image', scale='foo') self.assertTrue(foo.uid) self.assertEqual(foo.mimetype, 'image/jpeg') self.assertEqual(foo.width, 60) self.assertEqual(foo.height, 60) self.assertImage(foo.data, 'JPEG', (60, 60)) def testGetUnknownScale(self): foo = self.adapter.scale('image', scale='foo?') self.assertEqual(foo, None) def testScaleInvalidation(self): # first get the scale of the original image foo1 = self.adapter.scale('image', scale='foo') # now upload a new one and make sure the scale has changed self.image.update(image=self.getImage('image.jpg')) foo2 = self.adapter.scale('image', scale='foo') self.assertFalse(foo1.data == foo2.data, 'scale not updated?') def testCustomSizeChange(self): # set custom image sizes & view a scale self.iprops.manage_changeProperties(allowed_sizes=['foo 23:23']) foo = self.adapter.scale('image', scale='foo') self.assertEqual(foo.width, 23) self.assertEqual(foo.height, 23) # now let's update the scale dimensions, after which the scale # shouldn't be the same... self.iprops.manage_changeProperties(allowed_sizes=['foo 42:42']) foo = self.adapter.scale('image', scale='foo') self.assertEqual(foo.width, 42) self.assertEqual(foo.height, 42) def testQualityChange(self): iprops = self.portal.portal_properties.imaging_properties self.image.update(image=self.getImage('image.jpg')) data = self.getImage('image.jpg') + '\x00' * (1 << 16) # get size of image scaled at default scaling quality self.assertEqual(iprops.getProperty('quality'), 88) from Products.ATContentTypes.content.image import ATImage image = ATImage('image').__of__(self.folder) image.setImage(data) adapter = ImageScaling(image, None) img_high_quality = adapter.scale('image', width=100, height=80) size_high_quality = img_high_quality.size # lower scaling quality and get scaled image's size at that quality iprops.manage_changeProperties(quality=20) self.assertEqual(iprops.getProperty('quality'), 20) image = ATImage('image').__of__(self.folder) image.setImage(data) adapter = ImageScaling(image, None) img_low_quality = adapter.scale('image', width=100, height=80) size_low_quality = img_low_quality.size # data should be smaller at lower quality self.assertTrue(size_high_quality > size_low_quality) def testScaleThatCausesErrorsCanBeSuppressed(self): field = self.image.getField('image') field.swallowResizeExceptions = False self.assertRaises( Exception, self.adapter.scale, 'image', width=-1, height=-1) # scaling exceptions should be "swallowed" when set on the field... field.swallowResizeExceptions = True self.assertEqual(self.adapter.scale('image', width=-1, height=-1), None) def testGetAvailableSizes(self): assert self.adapter.getAvailableSizes('image') == {'foo': (60, 60)} def testGetImageSize(self): assert self.adapter.getImageSize('image') == (200, 200)
class ScalesAdapterTests(ImagingTestCase): def afterSetUp(self): data = self.getImage() folder = self.folder self.image = folder[folder.invokeFactory('Image', id='foo', image=data)] self.adapter = ImageScaling(self.image, None) self.iprops = self.portal.portal_properties.imaging_properties self.iprops.manage_changeProperties(allowed_sizes=['foo 60:60']) def testCreateScale(self): foo = self.adapter.scale('image', width=100, height=80) self.assertTrue(foo.uid) self.assertEqual(foo.mimetype, 'image/jpeg') self.assertEqual(foo.width, 80) self.assertEqual(foo.height, 80) self.assertImage(foo.data, 'JPEG', (80, 80)) def testCreateScaleWithoutData(self): folder = self.folder image = folder[folder.invokeFactory('Image', id='image')] adapter = ImageScaling(image, None) foo = adapter.scale('image', width=100, height=80) self.assertEqual(foo, None) def testCreateScaleWithPdata(self): data = self.getImage() + '\x00' * (1 << 16) from Products.ATContentTypes.content.image import ATImage image = ATImage('image').__of__(self.folder) image.setImage(data) field = image.getField('image') field.swallowResizeExceptions = False from OFS.Image import Pdata self.assertTrue(isinstance(image.getImage().data, Pdata)) adapter = ImageScaling(image, None) foo = adapter.scale('image', width=100, height=80) self.assertFalse(foo is None) def testGetScaleByName(self): foo = self.adapter.scale('image', scale='foo') self.assertTrue(foo.uid) self.assertEqual(foo.mimetype, 'image/jpeg') self.assertEqual(foo.width, 60) self.assertEqual(foo.height, 60) self.assertImage(foo.data, 'JPEG', (60, 60)) def testGetUnknownScale(self): foo = self.adapter.scale('image', scale='foo?') self.assertEqual(foo, None) def testScaleInvalidation(self): # first get the scale of the original image foo1 = self.adapter.scale('image', scale='foo') # now upload a new one and make sure the scale has changed self.image.update(image=self.getImage('image.jpg')) foo2 = self.adapter.scale('image', scale='foo') self.assertFalse(foo1.data == foo2.data, 'scale not updated?') def testCustomSizeChange(self): # set custom image sizes & view a scale self.iprops.manage_changeProperties(allowed_sizes=['foo 23:23']) foo = self.adapter.scale('image', scale='foo') self.assertEqual(foo.width, 23) self.assertEqual(foo.height, 23) # now let's update the scale dimensions, after which the scale # shouldn't be the same... self.iprops.manage_changeProperties(allowed_sizes=['foo 42:42']) foo = self.adapter.scale('image', scale='foo') self.assertEqual(foo.width, 42) self.assertEqual(foo.height, 42) def testQualityChange(self): iprops = self.portal.portal_properties.imaging_properties self.image.update(image=self.getImage('image.jpg')) data = self.getImage('image.jpg') + '\x00' * (1 << 16) # get size of image scaled at default scaling quality self.assertEqual(iprops.getProperty('quality'), 88) from Products.ATContentTypes.content.image import ATImage image = ATImage('image').__of__(self.folder) image.setImage(data) adapter = ImageScaling(image, None) img_high_quality = adapter.scale('image', width=100, height=80) size_high_quality = img_high_quality.size # lower scaling quality and get scaled image's size at that quality iprops.manage_changeProperties(quality=20) self.assertEqual(iprops.getProperty('quality'), 20) image = ATImage('image').__of__(self.folder) image.setImage(data) adapter = ImageScaling(image, None) img_low_quality = adapter.scale('image', width=100, height=80) size_low_quality = img_low_quality.size # data should be smaller at lower quality self.assertTrue(size_high_quality > size_low_quality) def testScaleThatCausesErrorsCanBeSuppressed(self): field = self.image.getField('image') field.swallowResizeExceptions = False self.assertRaises(Exception, self.adapter.scale, 'image', width=-1, height=-1) # scaling exceptions should be "swallowed" when set on the field... field.swallowResizeExceptions = True self.assertEqual(self.adapter.scale('image', width=-1, height=-1), None) def testGetAvailableSizes(self): assert self.adapter.getAvailableSizes('image') == {'foo': (60, 60)} def testGetImageSize(self): assert self.adapter.getImageSize('image') == (200, 200)
class ScalesAdapterTests(ReplacementTestCase, ImagingTestCaseMixin): def afterSetUp(self): data = self.getImage() folder = self.folder self.image = folder[folder.invokeFactory('Image', id='foo', image=data)] self.adapter = ImageScaling(self.image, None) self.iprops = self.portal.portal_properties.imaging_properties self.iprops.manage_changeProperties(allowed_sizes=['foo 60:60']) def testCreateScale(self): foo = self.adapter.scale('image', width=100, height=80) self.assertTrue(foo.uid) self.assertEqual(foo.mimetype, 'image/jpeg') self.assertEqual(foo.width, 80) self.assertEqual(foo.height, 80) self.assertImage(foo.data, 'JPEG', (80, 80)) def testCreateScaleWithoutData(self): folder = self.folder image = folder[folder.invokeFactory('Image', id='image')] adapter = ImageScaling(image, None) foo = adapter.scale('image', width=100, height=80) self.assertEqual(foo, None) def testGetScaleByName(self): foo = self.adapter.scale('image', scale='foo') self.assertTrue(foo.uid) self.assertEqual(foo.mimetype, 'image/jpeg') self.assertEqual(foo.width, 60) self.assertEqual(foo.height, 60) self.assertImage(foo.data, 'JPEG', (60, 60)) def testGetUnknownScale(self): foo = self.adapter.scale('image', scale='foo?') self.assertEqual(foo, None) def testScaleInvalidation(self): # first get the scale of the original image foo1 = self.adapter.scale('image', scale='foo') # now upload a new one and make sure the scale has changed self.image.update(image=self.getImage('image.jpg')) foo2 = self.adapter.scale('image', scale='foo') self.assertFalse(foo1.data == foo2.data, 'scale not updated?') def testCustomSizeChange(self): # set custom image sizes & view a scale self.iprops.manage_changeProperties(allowed_sizes=['foo 23:23']) foo = self.adapter.scale('image', scale='foo') self.assertEqual(foo.width, 23) self.assertEqual(foo.height, 23) # now let's update the scale dimensions, after which the scale # shouldn't be the same... self.iprops.manage_changeProperties(allowed_sizes=['foo 42:42']) foo = self.adapter.scale('image', scale='foo') self.assertEqual(foo.width, 42) self.assertEqual(foo.height, 42) def testScaleThatCausesErrorsCanBeSuppressed(self): field = self.image.getField('image') field.swallowResizeExceptions = False self.assertRaises(Exception, self.adapter.scale, 'image', direction='keep', width=42) # scaling exceptions should be "swallowed" when set on the field... field.swallowResizeExceptions = True self.assertEqual(self.adapter.scale('image', direction='keep', width=42), None)