@@ -62,7 +62,7 @@ def setup_class(cls):
6262 # set up mailhost so errors get reported to debuging capture file
6363 cls .db .config .MAILHOST = "localhost"
6464 cls .db .config .MAIL_HOST = "localhost"
65- cls .db .config .MAIL_DEBUG = "../mail .log.t "
65+ cls .db .config .MAIL_DEBUG = "../_test_tracker_mail .log"
6666
6767 # enable static precompressed files
6868 cls .db .config .WEB_USE_PRECOMPRESSED_FILES = 1
@@ -891,3 +891,81 @@ def test_cache_control_js(self):
891891 self .assertEqual (f .status_code , 200 )
892892 self .assertEqual (f .headers ['Cache-Control' ], 'public, max-age=1209600' )
893893
894+ def test_new_issue_with_file_upload (self ):
895+ # Set up session to manage cookies <insert blue monster here>
896+ session = requests .Session ()
897+
898+ # login using form
899+ login = {"__login_name" : 'admin' , '__login_password' : 'sekrit' ,
900+ "@action" : "login" }
901+ f = session .post (self .url_base ()+ '/' , data = login )
902+ # look for change in text in sidebar post login
903+ self .assertIn ('Hello, admin' , f .text )
904+
905+ # create a new issue and upload a file
906+ file_content = 'this is a test file\n '
907+ file = {"@file" : ('test1.txt' , file_content , "text/plain" ) }
908+ issue = {"title" : "my title" , "priority" : "1" , "@action" : "new" }
909+ f = session .post (self .url_base ()+ '/issue?@template=item' , data = issue , files = file )
910+ # we have an issue display, verify filename is listed there
911+ self .assertIn ("test1.txt" , f .text )
912+ # verify message in redirected url: file 1 created\nissue 1 created
913+ # warning may fail if another test loads tracker with files.
914+ self .assertEqual ('http://localhost:9001/issue1?@ok_message=file%201%20created%0Aissue%201%20created&@template=item' , f .url )
915+
916+ # download file and verify content
917+ f = session .get (self .url_base ()+ '/file1/text1.txt' )
918+ self .assertEqual (f .text , file_content )
919+ print (f .text )
920+
921+
922+ def test_new_file_via_rest (self ):
923+
924+ session = requests .Session ()
925+ session .auth = ('admin' , 'sekrit' )
926+
927+ url = self .url_base () + '/rest/data/'
928+ fname = 'a-bigger-testfile'
929+ d = dict (name = fname , type = 'application/octet-stream' )
930+ c = dict (content = r'xyzzy' )
931+ r = session .post (url + 'file' , files = c , data = d ,
932+ headers = {'x-requested-with' : "rest" }
933+ )
934+
935+ # was a 500 before fix for issue2551178
936+ self .assertEqual (r .status_code , 201 )
937+ # just compare the path leave off the number
938+ self .assertIn ('http://localhost:9001/rest/data/file/' ,
939+ r .headers ["location" ])
940+ json_dict = json .loads (r .text )
941+ self .assertEqual (json_dict ["data" ]["link" ], r .headers ["location" ])
942+
943+ # download file and verify content
944+ r = session .get (r .headers ["location" ] + '/content' )
945+ json_dict = json .loads (r .text )
946+ self .assertEqual (json_dict ['data' ]['data' ], c ["content" ])
947+ print (r .text )
948+
949+ # Upload a file via rest interface - no auth
950+ session .auth = None
951+ r = session .post (url + 'file' , files = c , data = d ,
952+ headers = {'x-requested-with' : "rest" }
953+ )
954+ self .assertEqual (r .status_code , 403 )
955+
956+ # get session variable from web form login
957+ # and use it to upload file
958+ # login using form
959+ login = {"__login_name" : 'admin' , '__login_password' : 'sekrit' ,
960+ "@action" : "login" }
961+ f = session .post (self .url_base ()+ '/' , data = login )
962+ # look for change in text in sidebar post login
963+ self .assertIn ('Hello, admin' , f .text )
964+
965+ r = session .post (url + 'file' , files = c , data = d ,
966+ headers = {'x-requested-with' : "rest" }
967+ )
968+ self .assertEqual (r .status_code , 201 )
969+ print (r .status_code )
970+
971+
0 commit comments