Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from plone/mamico-imagescaling
Fix imagescaling
- Loading branch information
Showing
5 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
import six | ||
import unittest | ||
|
||
from DateTime import DateTime | ||
from plone.app.testing import TEST_USER_ID | ||
from plone.app.testing import setRoles | ||
from plone.app.tiles.demo import PersistentTile | ||
from plone.app.tiles.testing import PLONE_APP_TILES_INTEGRATION_TESTING | ||
from plone.namedfile.file import NamedImage | ||
from plone.namedfile.tests import getFile | ||
from plone.tiles.interfaces import ITileDataManager | ||
|
||
|
||
class MockNamedImage(NamedImage): | ||
_p_mtime = DateTime().millis() | ||
|
||
|
||
class TestImageScaling(unittest.TestCase): | ||
|
||
layer = PLONE_APP_TILES_INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
self.request = self.layer['request'] | ||
# we need to have the Manager role to be able to add things | ||
# to the portal root | ||
setRoles(self.portal, TEST_USER_ID, ['Manager',]) | ||
|
||
def testImageScaling(self): | ||
tile = PersistentTile(self.portal, self.request) | ||
tile.id = 'mytile' | ||
data = getFile('image.png') | ||
data = { | ||
'message': u'foo', | ||
'image': MockNamedImage(data, 'image/png', u'image.png'), | ||
} | ||
dm = ITileDataManager(tile) | ||
dm.set(data) | ||
|
||
images = self.portal.restrictedTraverse('@@plone.app.tiles.demo.persistent/mytile/@@images') | ||
if six.PY2: | ||
assertRegex = self.assertRegexpMatches | ||
else: | ||
assertRegex = self.assertRegex | ||
|
||
assertRegex( | ||
images.tag('image', width=10), | ||
r'<img src="http://nohost/plone/@@plone.app.tiles.demo.persistent/mytile/@@images/[a-z0-9-]+\.png" ' | ||
r'alt="foo" title="foo" height="10" width="10" />' | ||
) | ||
|
||
scale = images.scale('image', scale='mini') | ||
self.assertEqual(scale.data.data[:4], b'\x89PNG') | ||
self.assertEqual(scale.data.getImageSize(), (200, 200)) | ||
assertRegex( | ||
scale.url, | ||
r'http://nohost/plone/@@plone.app.tiles.demo.persistent/mytile/@@images/[a-z0-9-]+\.png' | ||
) |