#NEWLINE# def test_image_upload_field( ) : #NEWLINE# #INDENT# app = Flask ( __name__ ) #NEWLINE# path = _create_temp ( ) #NEWLINE# def _remove_testimages( ) : #NEWLINE# #INDENT# safe_delete ( path , 'test1.png' ) #NEWLINE# safe_delete ( path , 'test1_thumb.jpg' ) #NEWLINE# safe_delete ( path , 'test2.png' ) #NEWLINE# safe_delete ( path , 'test2_thumb.jpg' ) #NEWLINE# safe_delete ( path , 'test1.jpg' ) #NEWLINE# safe_delete ( path , 'test1.jpeg' ) #NEWLINE# safe_delete ( path , 'test1.gif' ) #NEWLINE# safe_delete ( path , 'test1.png' ) #NEWLINE# safe_delete ( path , 'test1.tiff' ) #NEWLINE# #UNINDENT# class TestForm ( form . BaseForm ) : #NEWLINE# #INDENT# upload = form . ImageUploadField ( 'Upload' , base_path = path , thumbnail_size = ( 100 , 100 , True ) ) #NEWLINE# #UNINDENT# class TestNoResizeForm ( form . BaseForm ) : #NEWLINE# #INDENT# upload = form . ImageUploadField ( 'Upload' , base_path = path , endpoint = 'test' ) #NEWLINE# #UNINDENT# class TestAutoResizeForm ( form . BaseForm ) : #NEWLINE# #INDENT# upload = form . ImageUploadField ( 'Upload' , base_path = path , max_size = ( 64 , 64 , True ) ) #NEWLINE# #UNINDENT# class Dummy ( object ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# my_form = TestForm ( ) #NEWLINE# eq_ ( my_form . upload . base_path , path ) #NEWLINE# eq_ ( my_form . upload . endpoint , 'static' ) #NEWLINE# _remove_testimages ( ) #NEWLINE# dummy = Dummy ( ) #NEWLINE# filename = op . join ( op . dirname ( __file__ ) , 'data' , 'copyleft.png' ) #NEWLINE# with open ( filename , 'rb' ) as fp : #NEWLINE# #INDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( fp , 'test1.png' ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form = TestForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( my_form . validate ( ) ) #NEWLINE# my_form . populate_obj ( dummy ) #NEWLINE# eq_ ( dummy . upload , 'test1.png' ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test1.png' ) ) ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test1_thumb.png' ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# with open ( filename , 'rb' ) as fp : #NEWLINE# #INDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( fp , 'test2.png' ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form = TestForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( my_form . validate ( ) ) #NEWLINE# my_form . populate_obj ( dummy ) #NEWLINE# eq_ ( dummy . upload , 'test2.png' ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test2.png' ) ) ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test2_thumb.png' ) ) ) #NEWLINE# ok_ ( ( not op . exists ( op . join ( path , 'test1.png' ) ) ) ) #NEWLINE# ok_ ( ( not op . exists ( op . join ( path , 'test1_thumb.jpg' ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# '_upload-delete' : 'checked' , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form = TestForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( my_form . validate ( ) ) #NEWLINE# my_form . populate_obj ( dummy ) #NEWLINE# eq_ ( dummy . upload , None ) #NEWLINE# ok_ ( ( not op . exists ( op . join ( path , 'test2.png' ) ) ) ) #NEWLINE# ok_ ( ( not op . exists ( op . join ( path , 'test2_thumb.png' ) ) ) ) #NEWLINE# #UNINDENT# with open ( filename , 'rb' ) as fp : #NEWLINE# #INDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( fp , 'test1.png' ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form = TestNoResizeForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( my_form . validate ( ) ) #NEWLINE# my_form . populate_obj ( dummy ) #NEWLINE# eq_ ( dummy . upload , 'test1.png' ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test1.png' ) ) ) #NEWLINE# ok_ ( ( not op . exists ( op . join ( path , 'test1_thumb.png' ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# filename = op . join ( op . dirname ( __file__ ) , 'data' , 'copyleft.png' ) #NEWLINE# with open ( filename , 'rb' ) as fp : #NEWLINE# #INDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( fp , 'test1.png' ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form = TestAutoResizeForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( my_form . validate ( ) ) #NEWLINE# my_form . populate_obj ( dummy ) #NEWLINE# eq_ ( dummy . upload , 'test1.png' ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test1.png' ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# filename = op . join ( op . dirname ( __file__ ) , 'data' , 'copyleft.tiff' ) #NEWLINE# with open ( filename , 'rb' ) as fp : #NEWLINE# #INDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( fp , 'test1.tiff' ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form = TestAutoResizeForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( my_form . validate ( ) ) #NEWLINE# my_form . populate_obj ( dummy ) #NEWLINE# eq_ ( dummy . upload , 'test1.jpg' ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test1.jpg' ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# for extension in ( 'gif' , 'jpg' , 'jpeg' , 'png' , 'tiff' ) : #NEWLINE# #INDENT# filename = ( 'copyleft.' + extension ) #NEWLINE# filepath = op . join ( op . dirname ( __file__ ) , 'data' , filename ) #NEWLINE# with open ( filepath , 'rb' ) as fp : #NEWLINE# #INDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( fp , filename ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form = TestNoResizeForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( my_form . validate ( ) ) #NEWLINE# my_form . populate_obj ( dummy ) #NEWLINE# eq_ ( dummy . upload , my_form . upload . data . filename ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# filename = op . join ( op . dirname ( __file__ ) , 'data' , 'copyleft.jpg' ) #NEWLINE# with open ( filename , 'rb' ) as fp : #NEWLINE# #INDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( fp , 'copyleft.JPG' ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form = TestNoResizeForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( my_form . validate ( ) )