def test_original_format(): # handle_feed_images not specified, this tests the dependency ADDINS = [store_feed_images((tempdir, '%(model_id)s.%(extension)s'))] class TestImage(feedev.File): content = ValidPNGImage url = 'http://bla/stuff.png' class TestFeed(feedev.Feed): content = FeedWithImage % TestImage.url def pass1(feed): # check that the image was stored imgfile = path.join(tempdir, '%s.%s' % (feed.id, 'png')) assert path.exists(imgfile) # Make sure it was written correctly; this will usually not # be true if the image was saved using PIL, which is the # reason why we explicitely specify a url with an extension # to ``TestImage`` (otherwise, the image would be loaded into # PIL to defer the extension from the content), and PIL # subsequently used to save the file. assert open(imgfile, 'rb').read() == TestImage.content feedev.testcaller()
def init_config(): from feedplatform.lib import collect_feed_data, store_feed_images config.configure(**{ 'DATABASE': 'sqlite:%s' % dbfile, 'ADDINS': [ collect_feed_data('title'), store_feed_images((imgpath, '%(model_id)d.%(extension)s',)) ] })
def test_force_format(): ADDINS = [handle_feed_images, store_feed_images((tempdir, '%(model_id)s.gif'), format='gif')] class TestImage(feedev.File): content = ValidPNGImage class TestFeed(feedev.Feed): content = FeedWithImage % TestImage.url def pass1(feed): # check that the image was stored imgfile = path.join(tempdir, '%s.%s' % (feed.id, 'gif')) assert path.exists(imgfile) # check that it was stored as a true gif file from PIL import Image assert Image.open(imgfile).format == 'GIF' feedev.testcaller()