Changeset 15878 for main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/tests/test_browser.py
- Timestamp:
- 9 Dec 2019, 21:39:51 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/tests/test_browser.py
r15563 r15878 19 19 Test the applicant-related UI components. 20 20 """ 21 import grok 22 import datetime 23 import pytz 21 24 import os 22 import datetime 25 from StringIO import StringIO 26 from zope.event import notify 23 27 from zope.component import createObject, getUtility 24 28 from zope.catalog.interfaces import ICatalog 25 29 from zope.intid.interfaces import IIntIds 26 30 from hurry.workflow.interfaces import IWorkflowState 31 from zope.component import createObject, getUtility 32 from waeup.kofa.configuration import SessionConfiguration 33 from waeup.kofa.interfaces import ( 34 IUserAccount, IExtFileStore, IFileStoreNameChooser) 27 35 from kofacustom.iuokada.testing import FunctionalLayer 36 from waeup.kofa.applicants.container import ApplicantsContainer 28 37 from waeup.kofa.browser.tests.test_pdf import samples_dir 29 from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup 38 from waeup.kofa.applicants.tests.test_browser import (ApplicantsFullSetup, 39 ApplicantsFullSetup, container_name_1, session_1) 30 40 from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup 31 41 from kofacustom.iuokada.applicants.export import CustomApplicantExporter … … 91 101 open(path, 'wb').write(self.browser.contents) 92 102 print "Sample application_slip.pdf written to %s" % path 103 104 def test_upload_stateresult_by_manager(self): 105 # Add trans applicants container 106 self.transcontainer = ApplicantsContainer() 107 self.transcontainer.mode = 'create' 108 self.transcontainer.code = u'ug%s' % session_1 109 self.transcontainer.prefix = u'ug' 110 self.transcontainer.application_category = u'no' 111 self.transcontainer.year = session_1 112 self.transcontainer.application_fee = 300.0 113 self.transcontainer.title = u'This is the ug%s container' % session_1 114 self.app['applicants'][self.transcontainer.code] = self.transcontainer 115 delta = datetime.timedelta(days=10) 116 self.transcontainer.startdate = datetime.datetime.now(pytz.utc) - delta 117 self.transcontainer.enddate = datetime.datetime.now(pytz.utc) + delta 118 # Add applicant 119 transapplicant = createObject(u'waeup.Applicant') 120 transapplicant.firstname = u'Anna' 121 transapplicant.lastname = u'Post' 122 transapplicant.subtype = 'transfer' 123 self.app['applicants'][self.transcontainer.code].addApplicant(transapplicant) 124 self.transapplicant = self.app['applicants'][self.transcontainer.code][ 125 transapplicant.application_number] 126 self.transapplicant_view_path = ('http://localhost/app/applicants/ug%s/%s' 127 % (session_1, transapplicant.application_number)) 128 self.transapplicant_manage_path = ('http://localhost/app/applicants/ug%s/%s/manage' 129 % (session_1, transapplicant.application_number)) 130 # Login 131 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 132 self.browser.open(self.transapplicant_manage_path) 133 # Create a pseudo file with acceptable size 134 pdf_content = 'A' * 1024 * 300 # A string of 300 KB size 135 pseudo_pdf = StringIO(pdf_content) 136 ctrl = self.browser.getControl(name='form.stateresult') 137 file_ctrl = ctrl.mech_control 138 file_ctrl.add_file(pseudo_pdf, filename='myform.pdf') 139 self.browser.getControl("Save").click() # submit form 140 # Even though the form could not be saved ... 141 self.assertTrue('Required input is missing' in self.browser.contents) 142 # ... the file has been successfully uploaded 143 pdf_url = self.transapplicant_manage_path.replace('manage', 'stateresult.pdf') 144 self.browser.open(pdf_url) 145 self.assertEqual( 146 self.browser.headers['content-type'], 'application/pdf') 147 self.assertEqual(len(self.browser.contents), 307200) 148 # There is really a file stored for the applicant 149 storage = getUtility(IExtFileStore) 150 file_id = IFileStoreNameChooser(self.transapplicant).chooseName( 151 attr='stateresult.pdf') 152 # The stored file can be fetched 153 fd = storage.getFile(file_id) 154 file_len = len(fd.read()) 155 self.assertEqual(file_len, 307200) 156 # A file link is displayed on the edit view ... 157 self.browser.open(self.transapplicant_manage_path) 158 self.assertTrue('<a href="stateresult.pdf">' in self.browser.contents) 159 # ... and on the dislay view 160 self.browser.open(self.transapplicant_view_path) 161 self.assertTrue('stateresult.pdf">Statement of Result</a>' 162 in self.browser.contents) 163 # Adding file is properly logged 164 logfile = os.path.join( 165 self.app['datacenter'].storage, 'logs', 'applicants.log') 166 logcontent = open(logfile).read() 167 self.assertTrue( 168 'zope.mgr - kofacustom.iuokada.applicants.browser.CustomApplicantManageFormPage' 169 ' - %s - saved: stateresult' 170 % (self.transapplicant.applicant_id) 171 in logcontent) 172 # When an applicant is removed, also the pdf files are gone. 173 del self.app['applicants'][self.transcontainer.code][self.transapplicant.application_number] 174 fd = storage.getFile(file_id) 175 self.assertTrue(fd is None)
Note: See TracChangeset for help on using the changeset viewer.