<s> import os <EOL> from django . core . files . base import ContentFile <EOL> from easy_thumbnails . tests import utils , models <EOL> from easy_thumbnails . tests . test_aliases import BaseTest as AliasBaseTest <EOL> from easy_thumbnails . exceptions import ( <EOL> InvalidImageFormatError , EasyThumbnailsError ) <EOL> class ThumbnailerFieldTest ( AliasBaseTest ) : <EOL> def setUp ( self ) : <EOL> super ( ThumbnailerFieldTest , self ) . setUp ( ) <EOL> self . storage = utils . TemporaryStorage ( ) <EOL> self . create_image ( self . storage , '<STR_LIT>' ) <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> field = models . TestModel . _meta . get_field ( name ) <EOL> field . storage = self . storage <EOL> field . thumbnail_storage = self . storage <EOL> def tearDown ( self ) : <EOL> self . storage . delete_temporary_storage ( ) <EOL> super ( ThumbnailerFieldTest , self ) . tearDown ( ) <EOL> def test_generate_thumbnail ( self ) : <EOL> instance = models . TestModel ( avatar = '<STR_LIT>' ) <EOL> thumb = instance . avatar . generate_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT> , <NUM_LIT> ) } ) <EOL> self . assertEqual ( ( thumb . width , thumb . height ) , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> def test_generate_thumbnail_bad_image ( self ) : <EOL> text_file = ContentFile ( "<STR_LIT>" ) <EOL> self . storage . save ( '<STR_LIT>' , text_file ) <EOL> instance = models . TestModel ( avatar = '<STR_LIT>' ) <EOL> generate = lambda : instance . avatar . generate_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT> , <NUM_LIT> ) } ) <EOL> self . assertRaises ( IOError , generate ) <EOL> def test_generate_thumbnail_alias_bad_image ( self ) : <EOL> text_file = ContentFile ( "<STR_LIT>" ) <EOL> self . storage . save ( '<STR_LIT>' , text_file ) <EOL> instance = models . TestModel ( avatar = '<STR_LIT>' ) <EOL> generate = lambda : instance . avatar [ '<STR_LIT>' ] <EOL> self . assertRaises ( InvalidImageFormatError , generate ) <EOL> def test_generate_thumbnail_alias_0x0_size ( self ) : <EOL> instance = models . TestModel ( avatar = '<STR_LIT>' ) <EOL> self . assertRaises ( <EOL> EasyThumbnailsError , <EOL> instance . avatar . generate_thumbnail , { '<STR_LIT:size>' : ( <NUM_LIT:0> , <NUM_LIT:0> ) } ) <EOL> def test_delete ( self ) : <EOL> instance = models . TestModel ( avatar = '<STR_LIT>' ) <EOL> source_path = instance . avatar . path <EOL> thumb_paths = ( <EOL> instance . avatar . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT> , <NUM_LIT> ) } ) . path , <EOL> instance . avatar . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:200> , <NUM_LIT:200> ) } ) . path , <EOL> instance . avatar . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) . path , <EOL> ) <EOL> self . assertTrue ( os . path . exists ( source_path ) ) <EOL> for path in thumb_paths : <EOL> self . assertTrue ( os . path . exists ( path ) ) <EOL> instance . avatar . delete ( save = False ) <EOL> self . assertFalse ( os . path . exists ( source_path ) ) <EOL> for path in thumb_paths : <EOL> self . assertFalse ( os . path . exists ( path ) ) <EOL> def test_delete_thumbnails ( self ) : <EOL> instance = models . TestModel ( avatar = '<STR_LIT>' ) <EOL> source_path = instance . avatar . path <EOL> thumb_paths = ( <EOL> instance . avatar . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT> , <NUM_LIT> ) } ) . path , <EOL> instance . avatar . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:200> , <NUM_LIT:200> ) } ) . path , <EOL> instance . avatar . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) . path , <EOL> ) <EOL> self . assertTrue ( os . path . exists ( source_path ) ) <EOL> for path in thumb_paths : <EOL> self . assertTrue ( os . path . exists ( path ) ) <EOL> instance . avatar . delete_thumbnails ( ) <EOL> self . assertTrue ( os . path . exists ( source_path ) ) <EOL> for path in thumb_paths : <EOL> self . assertFalse ( os . path . exists ( path ) ) <EOL> def test_get_thumbnails ( self ) : <EOL> instance = models . TestModel ( avatar = '<STR_LIT>' ) <EOL> instance . avatar . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT> , <NUM_LIT> ) } ) <EOL> instance . avatar . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:200> , <NUM_LIT:200> ) } ) <EOL> self . assertEqual ( len ( list ( instance . avatar . get_thumbnails ( ) ) ) , <NUM_LIT:2> ) <EOL> def test_saving_image_field_with_resize_source ( self ) : <EOL> instance = models . TestModel ( avatar = '<STR_LIT>' ) <EOL> instance . picture . save ( <EOL> '<STR_LIT>' , ContentFile ( instance . avatar . file . read ( ) ) , save = False ) <EOL> self . assertEqual ( instance . picture . width , <NUM_LIT:10> ) <EOL> def test_saving_image_field_with_resize_source_different_ext ( self ) : <EOL> instance = models . TestModel ( avatar = '<STR_LIT>' ) <EOL> instance . picture . save ( <EOL> '<STR_LIT>' , ContentFile ( instance . avatar . file . read ( ) ) , save = False ) <EOL> self . assertEqual ( instance . picture . name , '<STR_LIT>' ) </s>
