示例#1
0
 def test_get_contenttype(self):
     self.assertEqual(
         get_contenttype(
             NamedImage(getFile('image.gif').read(),
                        contentType='image/gif')), 'image/gif')
     self.assertEqual(
         get_contenttype(
             NamedImage(getFile('image.gif').read(),
                        filename=u'image.gif')), 'image/gif')
     self.assertEqual(
         get_contenttype(
             NamedImage(getFile('notimage.doc').read(),
                        filename=u'notimage.doc')), 'application/msword')
示例#2
0
    def testImageValidation(self):
        from plone.namedfile.field import InvalidImageFile,\
            validate_image_field

        class FakeField(object):
            __name__ = 'logo'

        # field is empty
        validate_image_field(FakeField(), None)

        # field has an empty file
        image = self._makeImage()
        self.assertRaises(
            InvalidImageFile,
            validate_image_field,
            FakeField(),
            image)

        # field has an image file
        image._setData(zptlogo)
        validate_image_field(FakeField(), image)

        notimage = NamedImage(getFile('notimage.doc'),
                              filename=u'notimage.doc')
        self.assertRaises(
            InvalidImageFile,
            validate_image_field,
            FakeField(),
            notimage)
示例#3
0
 def setUp(self):
     data = getFile('image.png').read()
     item = DummyContent()
     item.image = NamedImage(data, 'image/png', u'image.png')
     self.layer['app']._setOb('item', item)
     self.item = self.layer['app'].item
     self.scaling = ImageScaling(self.item, None)
示例#4
0
 def setUp(self):
     data = getFile('image.png').read()
     item = DummyContent()
     item.image = NamedImage(data, 'image/png', u'image.png')
     self.layer['app']._setOb('item', item)
     self.item = self.layer['app'].item
     self.scaling = ImageScaling(self.item, None)
示例#5
0
    def testImageValidation(self):
        from plone.namedfile.field import InvalidImageFile
        from plone.namedfile.field import validate_image_field
        from plone.namedfile.interfaces import INamedImageField
        from zope.interface import implementer

        @implementer(INamedImageField)
        class FakeField(object):
            __name__ = 'logo'

        # field is empty
        validate_image_field(FakeField(), None)

        # field has an empty file
        image = self._makeImage()
        self.assertRaises(InvalidImageFile, validate_image_field, FakeField(),
                          image)

        # field has an image file
        image._setData(zptlogo)
        validate_image_field(FakeField(), image)

        notimage = NamedImage(getFile('notimage.doc'),
                              filename=u'notimage.doc')
        self.assertRaises(InvalidImageFile, validate_image_field, FakeField(),
                          notimage)
示例#6
0
 def setUp(self):
     self.app = self.layer['app']
     data = getFile('image.png').read()
     item = DummyContent()
     item.image = NamedImage(data, 'image/png', u'image.png')
     self.app._setOb('item', item)
     self.item = self.app.item
     self._orig_sizes = ImageScaling._sizes
示例#7
0
 def test_get_contenttype(self):
     self.assertEqual(
         get_contenttype(
             NamedImage(
                 getFile('image.gif'),
                 contentType='image/gif')),
         'image/gif')
     self.assertEqual(
         get_contenttype(
             NamedImage(
                 getFile('image.gif'),
                 filename=u'image.gif')),
         'image/gif')
     self.assertEqual(get_contenttype(
         NamedImage(getFile('notimage.doc'),
                    filename=u'notimage.doc')),
         'application/msword')
示例#8
0
 def setUp(self):
     self.app = self.layer['app']
     data = getFile('image.png').read()
     item = DummyContent()
     item.image = NamedImage(data, 'image/png', u'image.png')
     self.app._setOb('item', item)
     self.item = self.app.item
     self._orig_sizes = ImageScaling._sizes
示例#9
0
 def testScaleInvalidation(self):
     # first get the scale of the original image
     self.scaling.available_sizes = {'foo': (23, 23)}
     foo1 = self.scaling.scale('image', scale='foo')
     wait_to_ensure_modified()
     # now upload a new one and make sure the scale has changed
     data = getFile('image.jpg').read()
     self.item.image = NamedImage(data, 'image/jpeg', u'image.jpg')
     foo2 = self.scaling.scale('image', scale='foo')
     self.assertFalse(foo1.data == foo2.data, 'scale not updated?')
示例#10
0
 def testScaleInvalidation(self):
     # first get the scale of the original image
     self.scaling.available_sizes = {'foo': (23, 23)}
     foo1 = self.scaling.scale('image', scale='foo')
     wait_to_ensure_modified()
     # now upload a new one and make sure the scale has changed
     data = getFile('image.jpg').read()
     self.item.image = NamedImage(data, 'image/jpeg', u'image.jpg')
     foo2 = self.scaling.scale('image', scale='foo')
     self.assertFalse(foo1.data == foo2.data, 'scale not updated?')
    def setUp(self):
        data = getFile('image.png').read()
        item = DummyContent()
        item.image = NamedImage(data, 'image/png', u'image.png')
        self.layer['app']._setOb('item', item)
        self.item = self.layer['app'].item
        self.view = self.item.unrestrictedTraverse('@@images')
        self._orig_sizes = ImageScaling._sizes

        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.browser.addHeader('Referer', self.layer['app'].absolute_url())
示例#12
0
    def setUp(self):
        data = getFile('image.png').read()
        item = DummyContent()
        item.image = NamedImage(data, 'image/png', u'image.png')
        self.layer['app']._setOb('item', item)
        self.item = self.layer['app'].item
        self.view = self.item.unrestrictedTraverse('@@images')
        self._orig_sizes = ImageScaling._sizes

        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.browser.addHeader('Referer', self.layer['app'].absolute_url())
示例#13
0
 def test_opened_file_storable(self):
     data = getFile('image.gif')
     f = tempfile.NamedTemporaryFile(delete=False)
     try:
         path = f.name
         f.write(data)
         f.close()
         with open(path, 'rb') as f:
             fi = NamedBlobImage(f, filename=u'image.gif')
     finally:
         if os.path.exists(path):
             os.remove(path)
     self.assertEqual(303, fi.getSize())
    def setUp(self):
        if six.PY2:
            raise unittest.SkipTest('Disabled in py2 for now.')
        data = getFile('image.png')
        item = DummyContent()
        item.image = NamedImage(data, 'image/png', u'image.png')
        self.layer['app']._setOb('item', item)
        self.item = self.layer['app'].item
        self.view = self.item.unrestrictedTraverse('@@images')
        self._orig_sizes = ImageScaling._sizes

        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.browser.addHeader('Referer', self.layer['app'].absolute_url())
    def setUp(self):
        if six.PY2:
            raise unittest.SkipTest("Disabled in py2 for now.")
        data = getFile("image.png")
        item = DummyContent()
        item.image = NamedImage(data, "image/png", u"image.png")
        self.layer["app"]._setOb("item", item)
        self.item = self.layer["app"].item
        self.view = self.item.unrestrictedTraverse("@@images")
        self._orig_sizes = ImageScaling._sizes

        self.browser = Browser(self.layer["app"])
        self.browser.handleErrors = False
        self.browser.addHeader("Referer", self.layer["app"].absolute_url())
示例#16
0
 def testScaleInvalidation(self):
     # first view the thumbnail of the original image
     ImageScaling._sizes = {'thumb': (128, 128)}
     uid1, ext, width1, height1 = self.traverse('image/thumb')
     wait_to_ensure_modified()
     # now upload a new one and make sure the thumbnail has changed
     data = getFile('image.jpg').read()
     self.item.image = NamedImage(data, 'image/jpeg', u'image.jpg')
     uid2, ext, width2, height2 = self.traverse('image/thumb')
     self.assertNotEqual(uid1, uid2, 'thumb not updated?')
     # the height also differs as the original image had a size of 200, 200
     # whereas the updated one has 500, 200...
     self.assertEqual(width1, width2)
     self.assertNotEqual(height1, height2)
示例#17
0
    def test_dimension_int(self):

        self.assertEqual(dimension_int("auto"), 0)
        self.assertEqual(dimension_int("0"), 0)
        self.assertEqual(dimension_int("25"), 25)
        self.assertEqual(dimension_int("1024px"), 1024)
        self.assertEqual(dimension_int("123.0025px"), 123)
        self.assertEqual(dimension_int("123.625pt"), 123)
        self.assertEqual(dimension_int("50%"), 50)
        self.assertEqual(dimension_int(42), 42)
        self.assertEqual(dimension_int(6.25), 6)
        self.assertEqual(dimension_int({}), 0)
        self.assertEqual(dimension_int([]), 0)
        self.assertEqual(dimension_int(getFile('image.svg')), 0)
示例#18
0
 def testScaleInvalidation(self):
     # first view the thumbnail of the original image
     ImageScaling._sizes = {'thumb': (128, 128)}
     uid1, ext, width1, height1 = self.traverse('image/thumb')
     wait_to_ensure_modified()
     # now upload a new one and make sure the thumbnail has changed
     data = getFile('image.jpg').read()
     self.item.image = NamedImage(data, 'image/jpeg', u'image.jpg')
     uid2, ext, width2, height2 = self.traverse('image/thumb')
     self.assertNotEqual(uid1, uid2, 'thumb not updated?')
     # the height also differs as the original image had a size of 200, 200
     # whereas the updated one has 500, 200...
     self.assertEqual(width1, width2)
     self.assertNotEqual(height1, height2)
    def testSVGPublishThumbViaName(self):
        ImageScaling._sizes = {"thumb": (128, 128)}

        data = getFile("image.svg")
        svg = DummyContent()
        svg.image = NamedImage(data, "image/svg+xml", u"image.svg")
        self.layer["app"]._setOb("svg", svg)
        svg = self.layer["app"].svg

        transaction.commit()

        # make sure traversing works as is and with scaling
        # first the field without a scale name
        self.browser.open(self.layer["app"].absolute_url() + "/svg/@@images/image")

        self.assertEqual("image/svg+xml", self.browser.headers["content-type"])
        self.assertEqual(self.browser.contents, getFile("image.svg"))

        # and last a scaled version
        self.browser.open(
            self.layer["app"].absolute_url() + "/svg/@@images/image/thumb"
        )
        self.assertEqual("image/svg+xml", self.browser.headers["content-type"])
        self.assertEqual(self.browser.contents, data)
示例#20
0
    def testPublishThumbViaName(self):
        ImageScaling._sizes = {'thumb': (128, 128)}
        transaction.commit()

        # make sure traversing works as is and with scaling
        # first the field without a scale name
        self.browser.open(self.layer['app'].absolute_url() +
                          '/item/@@images/image')
        self.assertEqual('image/png', self.browser.headers['content-type'])
        self.assertEqual(self.browser.contents, getFile('image.png').read())

        # and last a scaled version
        self.browser.open(self.layer['app'].absolute_url() +
                          '/item/@@images/image/thumb')
        self.assertEqual('image/png', self.browser.headers['content-type'])
        assertImage(self, self.browser.contents, 'PNG', (128, 128))
    def testPublishThumbViaName(self):
        ImageScaling._sizes = {"thumb": (128, 128)}
        transaction.commit()

        # make sure traversing works as is and with scaling
        # first the field without a scale name
        self.browser.open(self.layer["app"].absolute_url() + "/item/@@images/image")
        self.assertEqual("image/png", self.browser.headers["content-type"])
        self.assertEqual(self.browser.contents, getFile("image.png"))

        # and last a scaled version
        self.browser.open(
            self.layer["app"].absolute_url() + "/item/@@images/image/thumb"
        )
        self.assertEqual("image/png", self.browser.headers["content-type"])
        assertImage(self, self.browser.contents, "PNG", (128, 128))
示例#22
0
    def testPublishThumbViaName(self):
        ImageScaling._sizes = {'thumb': (128, 128)}
        transaction.commit()

        # make sure traversing works as is and with scaling
        # first the field without a scale name
        self.browser.open(
            self.layer['app'].absolute_url() + '/item/@@images/image'
        )
        self.assertEqual('image/png', self.browser.headers['content-type'])
        self.assertEqual(self.browser.contents, getFile('image.png').read())

        # and last a scaled version
        self.browser.open(
            self.layer['app'].absolute_url() + '/item/@@images/image/thumb'
        )
        self.assertEqual('image/png', self.browser.headers['content-type'])
        assertImage(self, self.browser.contents, 'PNG', (128, 128))
示例#23
0
    def testScaledJpegImageQuality(self):
        """Test image quality setting for jpeg images.
        Image quality not available for PNG images.
        """
        data = getFile('image.jpg').read()
        item = DummyContent()
        item.image = NamedImage(data, 'image/jpeg', u'image.jpg')
        scaling = ImageScaling(item, None)

        # scale an image, record its size
        foo = scaling.scale('image', width=100, height=80)
        size_foo = foo.data.getSize()
        # let's pretend p.a.imaging set the scaling quality to "really sloppy"
        gsm = getGlobalSiteManager()
        qualitySupplier = DummyQualitySupplier()
        gsm.registerUtility(qualitySupplier.getQuality, IScaledImageQuality)
        wait_to_ensure_modified()
        # now scale again
        bar = scaling.scale('image', width=100, height=80)
        size_bar = bar.data.getSize()
        # first one should be bigger
        self.assertTrue(size_foo > size_bar)
示例#24
0
    def testScaledJpegImageQuality(self):
        """Test image quality setting for jpeg images.
        Image quality not available for PNG images.
        """
        data = getFile('image.jpg').read()
        item = DummyContent()
        item.image = NamedImage(data, 'image/png', u'image.jpg')
        scaling = ImageScaling(item, None)

        # scale an image, record its size
        foo = scaling.scale('image', width=100, height=80)
        size_foo = foo.data.getSize()
        # let's pretend p.a.imaging set the scaling quality to "really sloppy"
        gsm = getGlobalSiteManager()
        qualitySupplier = DummyQualitySupplier()
        gsm.registerUtility(qualitySupplier.getQuality, IScaledImageQuality)
        wait_to_ensure_modified()
        # now scale again
        bar = scaling.scale('image', width=100, height=80)
        size_bar = bar.data.getSize()
        # first one should be bigger
        self.assertTrue(size_foo > size_bar)
示例#25
0
 def test_str_storable(self):
     fi = NamedBlobImage(getFile('image.gif'), filename=u'image.gif')
     self.assertEqual(303, fi.getSize())
示例#26
0
 def test_pdata_storable(self):
     pdata = Pdata(getFile('image.gif').read())
     fi = NamedBlobImage(pdata, filename=u'image.gif')
     self.assertEqual(303, fi.getSize())
示例#27
0
 def test_filechunk_storable(self):
     fi = NamedBlobImage(FileChunk(getFile('image.gif').read()),
                         filename=u'image.gif')
     self.assertEqual(303, fi.getSize())
示例#28
0
    def test_process_svg(self):

        content_type, width, height = process_svg(getFile('image.svg'))
        self.assertEqual(content_type, "image/svg+xml")
        self.assertEqual(width, 158)
        self.assertEqual(height, 40)
示例#29
0
 def test_get_contenttype(self):
     self.assertEqual(
         get_contenttype(
             NamedImage(getFile('image.svg'), contentType='image/svg+xml')),
         'image/svg+xml')