@@ -726,6 +726,61 @@ def test_blackout_access(self):
726726 q = PyQuery (r .content )
727727 self .assertEqual (len (q ('input[type=file][name=txt]' )), 1 )
728728
729+ def submit_bad_file (self , name , formats ):
730+
731+ make_test_data ()
732+
733+ rev = ""
734+ group = None
735+
736+ # break early in case of missing configuration
737+ self .assertTrue (os .path .exists (settings .IDSUBMIT_IDNITS_BINARY ))
738+
739+ # get
740+ url = urlreverse ('submit_upload_submission' )
741+ r = self .client .get (url )
742+ self .assertEqual (r .status_code , 200 )
743+ q = PyQuery (r .content )
744+
745+ # submit
746+ files = {}
747+ for format in formats :
748+ files [format ] = self .submission_file (name , rev , group , "bad" , "test_submission.bad" )
749+
750+ r = self .client .post (url , files )
751+
752+ self .assertEqual (r .status_code , 200 )
753+ q = PyQuery (r .content )
754+ self .assertTrue (len (q ("form .has-error" )) > 0 )
755+ m = q ('div.has-error span.help-block' ).text ()
756+
757+ return r , q , m
758+
759+ def test_submit_bad_file_txt (self ):
760+ r , q , m = self .submit_bad_file ("some name" , ["txt" ])
761+ self .assertIn ('Invalid characters were found in the name' , m )
762+ self .assertIn ('Expected the TXT file to have extension ".txt"' , m )
763+ self .assertIn ('Expected an TXT file of type "text/plain"' , m )
764+ self .assertIn ('document does not contain a legitimate name' , m )
765+
766+ def test_submit_bad_file_xml (self ):
767+ r , q , m = self .submit_bad_file ("some name" , ["xml" ])
768+ self .assertIn ('Invalid characters were found in the name' , m )
769+ self .assertIn ('Expected the XML file to have extension ".xml"' , m )
770+ self .assertIn ('Expected an XML file of type "application/xml"' , m )
771+
772+ def test_submit_bad_file_pdf (self ):
773+ r , q , m = self .submit_bad_file ("some name" , ["pdf" ])
774+ self .assertIn ('Invalid characters were found in the name' , m )
775+ self .assertIn ('Expected the PDF file to have extension ".pdf"' , m )
776+ self .assertIn ('Expected an PDF file of type "application/pdf"' , m )
777+
778+ def test_submit_bad_file_ps (self ):
779+ r , q , m = self .submit_bad_file ("some name" , ["ps" ])
780+ self .assertIn ('Invalid characters were found in the name' , m )
781+ self .assertIn ('Expected the PS file to have extension ".ps"' , m )
782+ self .assertIn ('Expected an PS file of type "application/postscript"' , m )
783+
729784class ApprovalsTestCase (TestCase ):
730785 def test_approvals (self ):
731786 make_test_data ()
0 commit comments