1- import shutil , errno , pytest , json , gzip , os
1+ import shutil , errno , pytest , json , gzip , os , re
22
33from roundup .anypy .strings import b2s
44from roundup .cgi .wsgi_handler import RequestDispatcher
@@ -901,7 +901,6 @@ def test_cache_control_js(self):
901901 self .assertEqual (f .status_code , 200 )
902902 self .assertEqual (f .headers ['Cache-Control' ], 'public, max-age=1209600' )
903903
904- @pytest .mark .xfail (reason = "Work in progress" )
905904 def test_new_issue_with_file_upload (self ):
906905 # Set up session to manage cookies <insert blue monster here>
907906 session = requests .Session ()
@@ -918,14 +917,23 @@ def test_new_issue_with_file_upload(self):
918917 file = {"@file" : ('test1.txt' , file_content , "text/plain" ) }
919918 issue = {"title" : "my title" , "priority" : "1" , "@action" : "new" }
920919 f = session .post (self .url_base ()+ '/issue?@template=item' , data = issue , files = file )
921- # we have an issue display, verify filename is listed there
922- self .assertIn ("test1.txt" , f .text )
920+
921+ # use redirected url to determine which issue and file were created.
922+ m = re .search (r'[0-9]/issue(?P<issue>[0-9]+)\?@ok_message.*file%20(?P<file>[0-9]+)%20' , f .url )
923+
923924 # verify message in redirected url: file 1 created\nissue 1 created
924925 # warning may fail if another test loads tracker with files.
925- self .assertEqual ('http://localhost:9001/issue1?@ok_message=file%201%20created%0Aissue%201%20created&@template=item' , f .url )
926+ # Escape % signs in string by doubling them. This verifies the
927+ # search is working correctly.
928+ # use groupdict for python2.
929+ self .assertEqual ('http://localhost:9001/issue%(issue)s?@ok_message=file%%20%(file)s%%20created%%0Aissue%%20%(issue)s%%20created&@template=item' % m .groupdict (), f .url )
930+
931+ # we have an issue display, verify filename is listed there
932+ # seach for unique filename given to it.
933+ self .assertIn ("test1.txt" , f .text )
926934
927935 # download file and verify content
928- f = session .get (self .url_base ()+ '/file1 /text1.txt' )
936+ f = session .get (self .url_base ()+ '/file%(file)s /text1.txt' % m . groupdict () )
929937 self .assertEqual (f .text , file_content )
930938 print (f .text )
931939
0 commit comments