#NEWLINE# def test_upload_field( ) : #NEWLINE# #INDENT# app = Flask ( __name__ ) #NEWLINE# path = _create_temp ( ) #NEWLINE# def _remove_testfiles( ) : #NEWLINE# #INDENT# safe_delete ( path , 'test1.txt' ) #NEWLINE# safe_delete ( path , 'test2.txt' ) #NEWLINE# #UNINDENT# class TestForm ( form . BaseForm ) : #NEWLINE# #INDENT# upload = form . FileUploadField ( 'Upload' , base_path = path ) #NEWLINE# #UNINDENT# class TestNoOverWriteForm ( form . BaseForm ) : #NEWLINE# #INDENT# upload = form . FileUploadField ( 'Upload' , base_path = path , allow_overwrite = False ) #NEWLINE# #UNINDENT# class Dummy ( object ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# my_form = TestForm ( ) #NEWLINE# eq_ ( my_form . upload . base_path , path ) #NEWLINE# _remove_testfiles ( ) #NEWLINE# dummy = Dummy ( ) #NEWLINE# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( BytesIO ( b'Hello World 1' ) , 'test1.txt' ) , #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.txt' ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test1.txt' ) ) ) #NEWLINE# #UNINDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( BytesIO ( b'Hello World 2' ) , 'test2.txt' ) , #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.txt' ) #NEWLINE# ok_ ( ( not op . exists ( op . join ( path , 'test1.txt' ) ) ) ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test2.txt' ) ) ) #NEWLINE# #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.txt' ) ) ) ) #NEWLINE# #UNINDENT# _remove_testfiles ( ) #NEWLINE# my_form_ow = TestNoOverWriteForm ( ) #NEWLINE# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( BytesIO ( b'Hullo' ) , 'test1.txt' ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form_ow = TestNoOverWriteForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( my_form_ow . validate ( ) ) #NEWLINE# my_form_ow . populate_obj ( dummy ) #NEWLINE# eq_ ( dummy . upload , 'test1.txt' ) #NEWLINE# ok_ ( op . exists ( op . join ( path , 'test1.txt' ) ) ) #NEWLINE# #UNINDENT# with app . test_request_context ( method = 'POST' , data = { #NEWLINE# #INDENT# 'upload' : ( BytesIO ( b'Hullo' ) , 'test1.txt' ) , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# my_form_ow = TestNoOverWriteForm ( helpers . get_form_data ( ) ) #NEWLINE# ok_ ( ( not my_form_ow . validate ( ) ) ) #NEWLINE# #UNINDENT# _remove_testfiles ( )