Example #1
0
 def test__transform(self):
     item_name = u'image_Item'
     item = Binary.create(item_name)
     contenttype = u'image/jpeg'
     meta = {CONTENTTYPE: contenttype}
     item._save(meta)
     item = Binary.create(item_name)
     try:
         from PIL import Image as PILImage
         with pytest.raises(ValueError):
             result = TransformableBitmapImage._transform(item, 'text/plain')
     except ImportError:
         result = TransformableBitmapImage._transform(item, contenttype)
         assert result == (u'image/jpeg', '')
Example #2
0
 def test__render_data_diff_text(self):
     item_name = u'image_Item'
     item = Binary.create(item_name)
     contenttype = u'image/jpeg'
     meta = {CONTENTTYPE: contenttype}
     item._save(meta)
     item1 = Binary.create(item_name)
     data = 'test_data'
     comment = u'next revision'
     item1._save(meta, data, comment=comment)
     item2 = Binary.create(item_name)
     try:
         from PIL import Image as PILImage
         result = TransformableBitmapImage._render_data_diff_text(item1, item1.rev, item2.rev)
         expected = u'The items have different data.'
         assert result == expected
     except ImportError:
         pass
Example #3
0
 def test__render_data_diff(self):
     item_name = u'image_Item'
     item = Binary.create(item_name)
     contenttype = u'image/jpeg'
     meta = {CONTENTTYPE: contenttype}
     item._save(meta)
     item1 = Binary.create(item_name)
     try:
         from PIL import Image as PILImage
         result = Markup(TransformableBitmapImage._render_data_diff(item1, item.rev, item1.rev))
         # On Werkzeug 0.8.2+, urls with '+' are automatically encoded to '%2B'
         # The assert statement works with both older and newer versions of Werkzeug
         # Probably not an intentional change on the werkzeug side, see issue:
         # https://github.com/mitsuhiko/werkzeug/issues/146
         assert str(result).startswith('<img src="/+diffraw/image_Item?rev') or \
                 str(result).startswith('<img src="/%2Bdiffraw/image_Item?rev')
     except ImportError:
         # no PIL
         pass
Example #4
0
    def test_get_templates(self):
        item_name1 = u'Template_Item1'
        item1 = Binary.create(item_name1)
        contenttype1 = u'text/plain'
        meta = {CONTENTTYPE: contenttype1, 'tags': ['template']}
        item1._save(meta)
        item1 = Binary.create(item_name1)

        item_name2 = u'Template_Item2'
        item2 = Binary.create(item_name2)
        contenttype1 = u'text/plain'
        meta = {CONTENTTYPE: contenttype1, 'tags': ['template']}
        item2._save(meta)
        item2 = Binary.create(item_name2)

        item_name3 = u'Template_Item3'
        item3 = Binary.create(item_name3)
        contenttype2 = u'image/png'
        meta = {CONTENTTYPE: contenttype2, 'tags': ['template']}
        item3._save(meta)
        item3 = Binary.create(item_name3)
        # two items of same content type
        result1 = item1.get_templates(contenttype1)
        assert result1 == [item_name1, item_name2]
        # third of different content type
        result2 = item1.get_templates(contenttype2)
        assert result2 == [item_name3]