コード例 #1
0
 def testCreateScaleWithoutData(self):
     folder = self.folder
     image = folder[folder.invokeFactory('Image', id='image')]
     field = image.getField('image')
     handler = DefaultImageScaleHandler(field)
     foo = handler.createScale(image, 'foo', 100, 80)
     self.assertEqual(foo, None)
コード例 #2
0
ファイル: test_scaling.py プロジェクト: pigaov10/plone4.3
 def testCreateScaleWithoutData(self):
     folder = self.folder
     image = folder[folder.invokeFactory("Image", id="image")]
     field = image.getField("image")
     handler = DefaultImageScaleHandler(field)
     foo = handler.createScale(image, "foo", 100, 80)
     self.assertEqual(foo, None)
コード例 #3
0
 def testCreateScaleWithoutData(self):
     folder = self.folder
     image = folder[folder.invokeFactory('Image', id='image')]
     field = image.getField('image')
     handler = DefaultImageScaleHandler(field)
     foo = handler.createScale(image, 'foo', 100, 80)
     self.assertEqual(foo, None)
コード例 #4
0
 def afterSetUp(self):
     data = self.getImage()
     folder = self.folder
     self.image = folder[folder.invokeFactory('Image', id='foo', image=data)]
     self.field = self.image.getField('image')
     self.handler = DefaultImageScaleHandler(self.field)
     settings = getSettings()
     settings.allowed_sizes = [u'foo 60:60']
コード例 #5
0
 def afterSetUp(self):
     data = self.getImage()
     folder = self.folder
     self.image = folder[folder.invokeFactory('Image', id='foo',
                                              image=data)]
     self.field = self.image.getField('image')
     self.handler = DefaultImageScaleHandler(self.field)
     iprops = self.portal.portal_properties.imaging_properties
     iprops.manage_changeProperties(allowed_sizes=['foo 60:60'])
コード例 #6
0
class DefaultAdapterTests(ImagingTestCase):
    def afterSetUp(self):
        data = self.getImage()
        folder = self.folder
        self.image = folder[folder.invokeFactory('Image', id='foo',
                                                 image=data)]
        self.field = self.image.getField('image')
        self.handler = DefaultImageScaleHandler(self.field)
        settings = getSettings()
        settings.allowed_sizes = [u'foo 60:60']

    def testCreateScale(self):
        foo = self.handler.createScale(self.image, 'foo', 100, 80)
        self.assertEqual(foo['id'], 'image_foo')
        self.assertEqual(foo['content_type'], 'image/gif')
        self.assertEqual(foo['data'][:6], 'GIF87a')

    def testCreateScaleWithZeroWidth(self):
        foo = self.handler.createScale(self.image, 'foo', 100, 0)
        self.assertEqual(foo, None)

    def testCreateScaleWithoutData(self):
        folder = self.folder
        image = folder[folder.invokeFactory('Image', id='image')]
        field = image.getField('image')
        handler = DefaultImageScaleHandler(field)
        foo = handler.createScale(image, 'foo', 100, 80)
        self.assertEqual(foo, None)

    def testGetScale(self):
        foo = self.handler.getScale(self.image, 'foo')
        self.assertEqual(foo.getId(), 'image_foo')
        self.assertEqual(foo.getContentType(), 'image/gif')
        self.assertEqual(foo.data[:6], 'GIF87a')
        self.assertEqual(foo.width, 60)
        self.assertEqual(foo.height, 60)

    def testGetUnknownScale(self):
        foo = self.handler.getScale(self.image, 'foo?')
        self.assertEqual(foo, None)

    def testScaleThatCausesErrorsCanBeSuppressed(self):
        def causeError(*args, **kwargs):
            raise Exception

        _old_scale = self.field.scale
        self.field.scale = causeError
        self.field.swallowResizeExceptions = False
        self.assertRaises(Exception, self.handler.getScale, self.image, 'foo')
        # scaling exceptions should be "swallowed" when set on the field...
        self.field.swallowResizeExceptions = True
        self.assertEqual(self.handler.getScale(self.image, 'foo'), None)
        self.field.scale = _old_scale
コード例 #7
0
class DefaultAdapterTests(ImagingTestCase):

    def afterSetUp(self):
        data = self.getImage()
        folder = self.folder
        self.image = folder[folder.invokeFactory('Image', id='foo', image=data)]
        self.field = self.image.getField('image')
        self.handler = DefaultImageScaleHandler(self.field)
        iprops = self.portal.portal_properties.imaging_properties
        iprops.manage_changeProperties(allowed_sizes=['foo 60:60'])

    def testCreateScale(self):
        foo = self.handler.createScale(self.image, 'foo', 100, 80)
        self.assertEqual(foo['id'], 'image_foo')
        self.assertEqual(foo['content_type'], 'image/gif')
        self.assertEqual(foo['data'][:6], 'GIF87a')

    def testCreateScaleWithZeroWidth(self):
        foo = self.handler.createScale(self.image, 'foo', 100, 0)
        self.assertEqual(foo, None)

    def testCreateScaleWithoutData(self):
        folder = self.folder
        image = folder[folder.invokeFactory('Image', id='image')]
        field = image.getField('image')
        handler = DefaultImageScaleHandler(field)
        foo = handler.createScale(image, 'foo', 100, 80)
        self.assertEqual(foo, None)

    def testGetScale(self):
        foo = self.handler.getScale(self.image, 'foo')
        self.assertEqual(foo.getId(), 'image_foo')
        self.assertEqual(foo.getContentType(), 'image/gif')
        self.assertEqual(foo.data[:6], 'GIF87a')
        self.assertEqual(foo.width, 60)
        self.assertEqual(foo.height, 60)

    def testGetUnknownScale(self):
        foo = self.handler.getScale(self.image, 'foo?')
        self.assertEqual(foo, None)

    def testScaleThatCausesErrorsCanBeSuppressed(self):
        def causeError(*args, **kwargs):
            raise Exception
        _old_scale = self.field.scale
        self.field.scale = causeError
        self.field.swallowResizeExceptions = False
        self.assertRaises(Exception, self.handler.getScale, self.image, 'foo')
        # scaling exceptions should be "swallowed" when set on the field...
        self.field.swallowResizeExceptions = True
        self.assertEqual(self.handler.getScale(self.image, 'foo'), None)
        self.field.scale = _old_scale
コード例 #8
0
    def scaleToLargeRatios(self):
        """ Image ratio for the original image
        """
        field = self.context.getField(self.field_name)
        large_scale = field.getScale(self.context, 'large')
        if not large_scale:
            # Ok we don't have a 'large' scale, so we'll create one.
            handler = DefaultImageScaleHandler(field)
            data = handler.createScale(self.context, 'large', 768, 768)
            handler.storeScale(self.context, 'large', **data)
            large_scale = field.getScale(self.context, 'large')

        original = field.getScale(self.context)
        return (float(original.width) / float(large_scale.width),
                float(original.height) / float(large_scale.height),)
コード例 #9
0
    def scaleToLargeRatios(self):
        """ Image ratio for the original image
        """
        field = self.context.getField(self.field_name)
        large_scale = field.getScale(self.context, 'large')
        if not large_scale:
            # Ok we don't have a 'large' scale, so we'll create one.
            handler = DefaultImageScaleHandler(field)
            data = handler.createScale(self.context, 'large', 768, 768)
            handler.storeScale(self.context, 'large', **data)
            large_scale = field.getScale(self.context, 'large')

        original = field.getScale(self.context)
        return (
            float(original.width) / float(large_scale.width),
            float(original.height) / float(large_scale.height),
        )
コード例 #10
0
 def afterSetUp(self):
     data = self.getImage()
     folder = self.folder
     self.image = folder[folder.invokeFactory('Image', id='foo', image=data)]
     self.field = self.image.getField('image')
     self.handler = DefaultImageScaleHandler(self.field)
     iprops = self.portal.portal_properties.imaging_properties
     iprops.manage_changeProperties(allowed_sizes=['foo 60:60'])
コード例 #11
0
 def afterSetUp(self):
     data = self.getImage()
     folder = self.folder
     self.image = folder[folder.invokeFactory('Image', id='foo', image=data)]
     self.field = self.image.getField('image')
     self.handler = DefaultImageScaleHandler(self.field)
     settings = getSettings()
     settings.allowed_sizes = [u'foo 60:60']