- Timestamp:
- 29 Apr 2013, 08:18:41 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.futminna/trunk/src/waeup/futminna/applicants/tests/test_browser.py
r10096 r10105 65 65 self.assertTrue(img is None) 66 66 67 def test_upload_ formextension_by_student(self):67 def test_upload_extraform_by_student(self): 68 68 self.login() 69 69 self.browser.open(self.edit_path) … … 71 71 pdf_content = 'A' * 1024 * 600 # A string of 600 KB size 72 72 pseudo_pdf = StringIO(pdf_content) 73 ctrl = self.browser.getControl(name='form. formextension')73 ctrl = self.browser.getControl(name='form.extraform') 74 74 file_ctrl = ctrl.mech_control 75 75 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') … … 81 81 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 82 82 pseudo_pdf = StringIO(pdf_content) 83 ctrl = self.browser.getControl(name='form. formextension')84 file_ctrl = ctrl.mech_control 85 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 86 self.browser.getControl("Save").click() # submit form 87 # Even though the form could not be saved ... 88 self.assertTrue('Required input is missing' in self.browser.contents) 89 # ... the file has been successfully uploaded 90 pdf_url = self.edit_path.replace('edit', ' formextension.pdf')83 ctrl = self.browser.getControl(name='form.extraform') 84 file_ctrl = ctrl.mech_control 85 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 86 self.browser.getControl("Save").click() # submit form 87 # Even though the form could not be saved ... 88 self.assertTrue('Required input is missing' in self.browser.contents) 89 # ... the file has been successfully uploaded 90 pdf_url = self.edit_path.replace('edit', 'extraform.pdf') 91 91 self.browser.open(pdf_url) 92 92 self.assertEqual( … … 96 96 storage = getUtility(IExtFileStore) 97 97 file_id = IFileStoreNameChooser(self.applicant).chooseName( 98 attr=' formextension.pdf')99 # The stored file can be fetched 100 fd = storage.getFile(file_id) 101 file_len = len(fd.read()) 102 self.assertEqual(file_len, 307200) 103 # A file link is displayed on the edit view ... 104 self.browser.open(self.edit_path) 105 self.assertTrue('<a href=" formextension.pdf">' in self.browser.contents)106 # ... and on the dislay view 107 self.browser.open(self.view_path) 108 self.assertTrue('<a href=" formextension.pdf">Offline Form Extension</a>'109 in self.browser.contents) 110 111 def test_upload_ formextension_by_manager(self):98 attr='extraform.pdf') 99 # The stored file can be fetched 100 fd = storage.getFile(file_id) 101 file_len = len(fd.read()) 102 self.assertEqual(file_len, 307200) 103 # A file link is displayed on the edit view ... 104 self.browser.open(self.edit_path) 105 self.assertTrue('<a href="extraform.pdf">' in self.browser.contents) 106 # ... and on the dislay view 107 self.browser.open(self.view_path) 108 self.assertTrue('<a href="extraform.pdf">Extra Applicant Information Form</a>' 109 in self.browser.contents) 110 111 def test_upload_extraform_by_manager(self): 112 112 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 113 113 self.browser.open(self.manage_path) … … 115 115 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 116 116 pseudo_pdf = StringIO(pdf_content) 117 ctrl = self.browser.getControl(name='form. formextension')118 file_ctrl = ctrl.mech_control 119 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 120 self.browser.getControl("Save").click() # submit form 121 # Even though the form could not be saved ... 122 self.assertTrue('Required input is missing' in self.browser.contents) 123 # ... the file has been successfully uploaded 124 pdf_url = self.manage_path.replace('manage', ' formextension.pdf')117 ctrl = self.browser.getControl(name='form.extraform') 118 file_ctrl = ctrl.mech_control 119 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 120 self.browser.getControl("Save").click() # submit form 121 # Even though the form could not be saved ... 122 self.assertTrue('Required input is missing' in self.browser.contents) 123 # ... the file has been successfully uploaded 124 pdf_url = self.manage_path.replace('manage', 'extraform.pdf') 125 125 self.browser.open(pdf_url) 126 126 self.assertEqual( … … 130 130 storage = getUtility(IExtFileStore) 131 131 file_id = IFileStoreNameChooser(self.applicant).chooseName( 132 attr=' formextension.pdf')133 # The stored file can be fetched 134 fd = storage.getFile(file_id) 135 file_len = len(fd.read()) 136 self.assertEqual(file_len, 307200) 137 # A file link is displayed on the edit view ... 138 self.browser.open(self.manage_path) 139 self.assertTrue('<a href=" formextension.pdf">' in self.browser.contents)140 # ... and on the dislay view 141 self.browser.open(self.view_path) 142 self.assertTrue('<a href=" formextension.pdf">Offline Form Extension</a>'132 attr='extraform.pdf') 133 # The stored file can be fetched 134 fd = storage.getFile(file_id) 135 file_len = len(fd.read()) 136 self.assertEqual(file_len, 307200) 137 # A file link is displayed on the edit view ... 138 self.browser.open(self.manage_path) 139 self.assertTrue('<a href="extraform.pdf">' in self.browser.contents) 140 # ... and on the dislay view 141 self.browser.open(self.view_path) 142 self.assertTrue('<a href="extraform.pdf">Extra Applicant Information Form</a>' 143 143 in self.browser.contents) 144 144 # Adding file is properly logged … … 148 148 self.assertTrue( 149 149 'zope.mgr - waeup.futminna.applicants.browser.CustomApplicantManageFormPage' 150 ' - %s - saved: formextension'150 ' - %s - saved: extraform' 151 151 % (self.applicant.applicant_id) 152 152 in logcontent) 153 154 def test_upload_refereeform_by_student(self): 155 self.login() 156 self.browser.open(self.edit_path) 157 # Create a pseudo file and select it to be uploaded in form 158 pdf_content = 'A' * 1024 * 600 # A string of 600 KB size 159 pseudo_pdf = StringIO(pdf_content) 160 ctrl = self.browser.getControl(name='form.refereeform') 161 file_ctrl = ctrl.mech_control 162 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 163 self.browser.getControl("Save").click() # submit form 164 # We get a warning message 165 self.assertTrue( 166 'Uploaded file is too big' in self.browser.contents) 167 # Create a pseudo file with acceptable size 168 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 169 pseudo_pdf = StringIO(pdf_content) 170 ctrl = self.browser.getControl(name='form.refereeform') 171 file_ctrl = ctrl.mech_control 172 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 173 self.browser.getControl("Save").click() # submit form 174 # Even though the form could not be saved ... 175 self.assertTrue('Required input is missing' in self.browser.contents) 176 # ... the file has been successfully uploaded 177 pdf_url = self.edit_path.replace('edit', 'refereeform.pdf') 178 self.browser.open(pdf_url) 179 self.assertEqual( 180 self.browser.headers['content-type'], 'application/pdf') 181 self.assertEqual(len(self.browser.contents), 307200) 182 # There is really a file stored for the applicant 183 storage = getUtility(IExtFileStore) 184 file_id = IFileStoreNameChooser(self.applicant).chooseName( 185 attr='refereeform.pdf') 186 # The stored file can be fetched 187 fd = storage.getFile(file_id) 188 file_len = len(fd.read()) 189 self.assertEqual(file_len, 307200) 190 # A file link is displayed on the edit view ... 191 self.browser.open(self.edit_path) 192 self.assertTrue('<a href="refereeform.pdf">' in self.browser.contents) 193 # ... and on the dislay view 194 self.browser.open(self.view_path) 195 self.assertTrue('<a href="refereeform.pdf">Referee\'s Form</a>' 196 in self.browser.contents) 197 198 def test_upload_refereeform_by_manager(self): 199 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 200 self.browser.open(self.manage_path) 201 # Create a pseudo file with acceptable size 202 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 203 pseudo_pdf = StringIO(pdf_content) 204 ctrl = self.browser.getControl(name='form.refereeform') 205 file_ctrl = ctrl.mech_control 206 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 207 self.browser.getControl("Save").click() # submit form 208 # Even though the form could not be saved ... 209 self.assertTrue('Required input is missing' in self.browser.contents) 210 # ... the file has been successfully uploaded 211 pdf_url = self.manage_path.replace('manage', 'refereeform.pdf') 212 self.browser.open(pdf_url) 213 self.assertEqual( 214 self.browser.headers['content-type'], 'application/pdf') 215 self.assertEqual(len(self.browser.contents), 307200) 216 # There is rally a file stored for the applicant 217 storage = getUtility(IExtFileStore) 218 file_id = IFileStoreNameChooser(self.applicant).chooseName( 219 attr='refereeform.pdf') 220 # The stored file can be fetched 221 fd = storage.getFile(file_id) 222 file_len = len(fd.read()) 223 self.assertEqual(file_len, 307200) 224 # A file link is displayed on the edit view ... 225 self.browser.open(self.manage_path) 226 self.assertTrue('<a href="refereeform.pdf">' in self.browser.contents) 227 # ... and on the dislay view 228 self.browser.open(self.view_path) 229 self.assertTrue('<a href="refereeform.pdf">Referee\'s Form</a>' 230 in self.browser.contents) 231 # Adding file is properly logged 232 logfile = os.path.join( 233 self.app['datacenter'].storage, 'logs', 'applicants.log') 234 logcontent = open(logfile).read() 235 self.assertTrue( 236 'zope.mgr - waeup.futminna.applicants.browser.CustomApplicantManageFormPage' 237 ' - %s - saved: refereeform' 238 % (self.applicant.applicant_id) 239 in logcontent)
Note: See TracChangeset for help on using the changeset viewer.