Пример #1
0
    def test_unistalled(self):
        """ Validate that our product doesn't modify images if not installed
        """
        login(self.portal, TEST_USER_NAME)

        self.portal.invokeFactory('Image', 'test_jpeg_image')
        self.portal['test_jpeg_image'].setImage(generate_jpeg(100, 100))
        zope.event.notify(ObjectModifiedEvent(self.portal['test_jpeg_image']))
        self.portal.invokeFactory('Image', 'test_gif_image')
        self.portal['test_gif_image'].setImage(generate_gif(100, 100))
        zope.event.notify(ObjectModifiedEvent(self.portal['test_gif_image']))

        im = Image.open(StringIO(self.portal['test_jpeg_image'].getImage()))
        self.assertEqual(im.format, 'JPEG')

        im = Image.open(StringIO(self.portal['test_gif_image'].getImage()))
        self.assertEqual(im.format, 'GIF')
Пример #2
0
    def test_unistalled(self):
        """ Validate that our product doesn't modify images if not installed
        """
        login(self.portal, TEST_USER_NAME)
        qi_tool = getToolByName(self.portal, 'portal_quickinstaller')
        qi_tool.uninstallProducts(['openmultimedia.imagewatchdog'])

        self.portal.invokeFactory('Image', 'test_jpeg_image')
        self.portal['test_jpeg_image'].setImage(generate_jpeg(100, 100))
        zope.event.notify(ObjectModifiedEvent(self.portal['test_jpeg_image']))
        self.portal.invokeFactory('Image', 'test_gif_image')
        self.portal['test_gif_image'].setImage(generate_gif(100, 100))
        zope.event.notify(ObjectModifiedEvent(self.portal['test_gif_image']))

        im = Image.open(StringIO(self.portal['test_jpeg_image'].getImage()))
        self.assertEqual(im.format, 'JPEG')

        im = Image.open(StringIO(self.portal['test_gif_image'].getImage()))
        self.assertEqual(im.format, 'GIF')
Пример #3
0
    def test_enabled(self):
        """ Validate that images are transformed to PNG if enabled
        """
        login(self.portal, TEST_USER_NAME)
        registry = getUtility(IRegistry)
        settings = registry.forInterface(IImageWatchDogSettings)
        settings.enabled = True

        self.portal.invokeFactory('Image', 'test_jpeg_image')
        self.portal['test_jpeg_image'].setImage(generate_jpeg(100, 100))
        zope.event.notify(ObjectModifiedEvent(self.portal['test_jpeg_image']))
        self.portal.invokeFactory('Image', 'test_gif_image')
        self.portal['test_gif_image'].setImage(generate_gif(100, 100))
        zope.event.notify(ObjectModifiedEvent(self.portal['test_gif_image']))

        im = Image.open(StringIO(self.portal['test_jpeg_image'].getImage()))
        self.assertEqual(im.format, 'PNG')

        im = Image.open(StringIO(self.portal['test_gif_image'].getImage()))
        self.assertEqual(im.format, 'PNG')
Пример #4
0
    def test_disabled(self):
        """ Validate that our product doesn't modify images if disabled
        """
        login(self.portal, TEST_USER_NAME)
        registry = getUtility(IRegistry)
        settings = registry.forInterface(IImageWatchDogSettings)
        self.assertFalse(settings.enabled)

        self.portal.invokeFactory('Image', 'test_jpeg_image')
        self.portal['test_jpeg_image'].setImage(generate_jpeg(100, 100))
        zope.event.notify(ObjectModifiedEvent(self.portal['test_jpeg_image']))
        self.portal.invokeFactory('Image', 'test_gif_image')
        self.portal['test_gif_image'].setImage(generate_gif(100, 100))
        zope.event.notify(ObjectModifiedEvent(self.portal['test_gif_image']))

        im = Image.open(StringIO(self.portal['test_jpeg_image'].getImage()))
        self.assertEqual(im.format, 'JPEG')

        im = Image.open(StringIO(self.portal['test_gif_image'].getImage()))
        self.assertEqual(im.format, 'GIF')