예제 #1
0
    def test_image_formats(self):
        """make sure the scales have the same format as the original image
        """

        from cStringIO import StringIO
        from PIL.Image import open
        org_data = StringIO(self.img.image.data)
        self.assertEqual(open(org_data).format, 'PNG')

        view = self.img.restrictedTraverse('@@crop-image')
        view._crop(fieldname='image', scale='thumb', box=(14, 14, 218, 218))
        traverse = self.portal.REQUEST.traverseName

        scales = traverse(self.img, '@@images')
        cropped = scales.scale('image', 'thumb')
        croppedData = StringIO(cropped.data._data)
        self.assertEqual(
            open(croppedData).format,
            'PNG',
            'cropped scale does not have same format as the original'
        )

        # create a jpeg image out of the png file
        # and test if created scale is jpeg too
        _createObjectByType('Image', self.portal, 'testjpeg')
        jpg = self.portal.testjpeg
        jpg.image = dummy_named_blob_jpg_image()

        org_data = StringIO(jpg.image.data)
        self.assertEqual(open(org_data).format, 'JPEG')

        view = jpg.restrictedTraverse('@@crop-image')
        view._crop(fieldname='image', scale='thumb', box=(14, 14, 218, 218))
        cropped = scales.scale('image', 'thumb')
        croppedData = StringIO(cropped.data._data)
    def test_image_formats(self):
        """make sure the scales have the same format as the original image
        """

        from cStringIO import StringIO
        from PIL.Image import open
        org_data = StringIO(self.img.image.data)
        self.assertEqual(open(org_data).format, 'PNG')

        view = self.img.restrictedTraverse('@@crop-image')
        view._crop(fieldname='image', scale='thumb', box=(14, 14, 218, 218))
        traverse = self.portal.REQUEST.traverseName

        scales = traverse(self.img, '@@images')
        cropped = scales.scale('image', 'thumb')
        croppedData = StringIO(cropped.data._data)
        self.assertEqual(
            open(croppedData).format, 'PNG',
            'cropped scale does not have same format as the original')

        # create a jpeg image out of the png file
        # and test if created scale is jpeg too
        _createObjectByType('Image', self.portal, 'testjpeg')
        jpg = self.portal.testjpeg
        jpg.image = dummy_named_blob_jpg_image()

        org_data = StringIO(jpg.image.data)
        self.assertEqual(open(org_data).format, 'JPEG')

        view = jpg.restrictedTraverse('@@crop-image')
        view._crop(fieldname='image', scale='thumb', box=(14, 14, 218, 218))
        cropped = scales.scale('image', 'thumb')
        croppedData = StringIO(cropped.data._data)
    def test_modify_image(self):
        """set a different image, this should invalidate scales

        see and https://github.com/collective/plone.app.imagecropping/issues/54
        """

        view = self.img.restrictedTraverse('@@crop-image')
        traverse = self.portal.REQUEST.traverseName
        scales = traverse(self.img, '@@images')

        # store cropped version for thumb and check if the result
        # is a square now
        view._crop(fieldname='image', scale='thumb', box=(14, 14, 218, 218))
        cropped = scales.scale('image', 'thumb')
        self.assertEqual((cropped.width, cropped.height), (128, 128))

        # upload another image file
        self.img.image = dummy_named_blob_jpg_image()
        event.notify(ObjectModifiedEvent(self.img))

        # XXX: traversal does not seem to work in the DX test fixture
        # jpeg_thumb_attr = traverse(self.img, 'image_thumb')
        # self.assertNotEqual(
        #     (jpeg_thumb_attr.width, jpeg_thumb_attr.height),
        #     (128, 128),
        #     'context/image_thumb returns old cropped scale after '
        #     'setting a new image'
        # )

        jpeg_thumb = scales.scale('image', 'thumb')
        self.assertNotEqual(
            (jpeg_thumb.width, jpeg_thumb.height), (128, 128),
            'context/@@images/image/thumb returns old cropped scale after '
            'setting a new image')
예제 #4
0
    def test_modify_image(self):
        """set a different image, this should invalidate scales

        see and https://github.com/collective/plone.app.imagecropping/issues/54
        """

        view = self.img.restrictedTraverse('@@crop-image')
        traverse = self.portal.REQUEST.traverseName
        scales = traverse(self.img, '@@images')

        # store cropped version for thumb and check if the result
        # is a square now
        view._crop(fieldname='image', scale='thumb', box=(14, 14, 218, 218))
        cropped = scales.scale('image', 'thumb')
        self.assertEqual((cropped.width, cropped.height), (128, 128))

        # upload another image file
        self.img.image = dummy_named_blob_jpg_image()
        event.notify(ObjectModifiedEvent(self.img))

        # XXX: traversal does not seem to work in the DX test fixture
        # jpeg_thumb_attr = traverse(self.img, 'image_thumb')
        # self.assertNotEqual(
        #     (jpeg_thumb_attr.width, jpeg_thumb_attr.height),
        #     (128, 128),
        #     'context/image_thumb returns old cropped scale after '
        #     'setting a new image'
        # )

        jpeg_thumb = scales.scale('image', 'thumb')
        self.assertNotEqual(
            (jpeg_thumb.width, jpeg_thumb.height),
            (128, 128),
            'context/@@images/image/thumb returns old cropped scale after '
            'setting a new image'
        )