- Timestamp:
- 23 Jan 2020, 12:25:29 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r15578 r15943 1278 1278 '<option selected="selected" value="CERT1">' 1279 1279 in self.browser.contents) 1280 1281 def test_upload_testfile(self): 1282 self.login() 1283 self.browser.open(self.edit_path) 1284 self.fill_correct_values() # fill other fields with correct values 1285 # Create a pseudo file with acceptable size 1286 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 1287 pseudo_pdf = StringIO(pdf_content) 1288 ctrl = self.browser.getControl(name='testfile.pdf') 1289 file_ctrl = ctrl.mech_control 1290 file_ctrl.add_file(pseudo_pdf, filename='testfile.pdf') 1291 self.browser.getControl("Save").click() # submit form 1292 self.assertTrue('Uploaded file is too big!' 1293 in self.browser.contents) 1294 pdf_content = 'A' * 1024 * 200 # A string of 300 KB size 1295 pseudo_pdf = StringIO(pdf_content) 1296 ctrl = self.browser.getControl(name='testfile.pdf') 1297 file_ctrl = ctrl.mech_control 1298 file_ctrl.add_file(pseudo_pdf, filename='testfile.pdf') 1299 self.browser.getControl("Save").click() # submit form 1300 # The file has been successfully uploaded 1301 self.assertTrue('Form has been saved.' in self.browser.contents) 1302 # There is really a file stored for the applicant 1303 storage = getUtility(IExtFileStore) 1304 file_id = IFileStoreNameChooser(self.applicant).chooseName( 1305 attr='testfile.pdf') 1306 # The stored file can be fetched 1307 fd = storage.getFile(file_id) 1308 file_len = len(fd.read()) 1309 self.assertEqual(file_len, 204800) 1310 # A file link is displayed on the edit view ... 1311 self.browser.open(self.edit_path) 1312 self.assertTrue('<a href="testfile.pdf">' in self.browser.contents) 1313 # ... and on the dislay view 1314 self.browser.open(self.view_path) 1315 self.assertTrue('testfile.pdf">Test File</a>' 1316 in self.browser.contents) 1317 # Adding file is properly logged 1318 logfile = os.path.join( 1319 self.app['datacenter'].storage, 'logs', 'applicants.log') 1320 logcontent = open(logfile).read() 1321 self.assertTrue( 1322 '%s - applicants.browser.ApplicantEditFormPage' 1323 ' - %s - saved: testfile.pdf' 1324 % (self.applicant.applicant_id, self.applicant.applicant_id) 1325 in logcontent) 1326 # When an applicant is removed, also the pdf files are gone. 1327 del self.applicantscontainer[self.applicant.application_number] 1328 fd = storage.getFile(file_id) 1329 self.assertTrue(fd is None) 1330 return 1331 1280 1332 1281 1333 class ApplicantRegisterTests(ApplicantsFullSetup):
Note: See TracChangeset for help on using the changeset viewer.