Changeset 9217 for main/waeup.kofa/trunk/src/waeup/kofa/browser/tests
- Timestamp:
- 21 Sep 2012, 11:21:05 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/browser/tests
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py
r9034 r9217 21 21 import shutil 22 22 import tempfile 23 import pytz24 from datetime import datetime, timedelta25 from StringIO import StringIO26 23 import os 27 import grok 28 from zope.event import notify 29 from zope.component import createObject, queryUtility 24 from zc.async.testing import wait_for_result 25 from zope.component import createObject, getUtility 30 26 from zope.component.hooks import setSite, clearSite 31 from zope.catalog.interfaces import ICatalog32 27 from zope.security.interfaces import Unauthorized 33 from zope.securitypolicy.interfaces import IPrincipalRoleManager34 28 from zope.testbrowser.testing import Browser 35 from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState36 29 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 37 30 from waeup.kofa.app import University 31 from waeup.kofa.interfaces import IJobManager 32 from waeup.kofa.tests.test_async import FunctionalAsyncTestCase 38 33 from waeup.kofa.university.faculty import Faculty 39 34 from waeup.kofa.university.department import Department … … 106 101 shutil.rmtree(self.dc_root) 107 102 108 109 103 class DataCenterUITests(UniversitySetup): 110 104 # Tests for DataCenter class views and pages … … 149 143 return 150 144 151 def test_export(self): 145 146 class DataCenterUIExportTests(UniversitySetup, FunctionalAsyncTestCase): 147 # Tests for DataCenter class views and pages 148 149 layer = FunctionalLayer 150 151 def wait_for_export_job_completed(self): 152 # helper function waiting until the current export job is completed 153 manager = getUtility(IJobManager) 154 job_id = self.app['datacenter'].running_exports[0][0] 155 job = manager.get(job_id) 156 wait_for_result(job) 157 return job_id 158 159 def stored_in_datacenter(self, job_id): 160 # tell whether job_id is stored in datacenter's running jobs list 161 for entry in list(self.app['datacenter'].running_exports): 162 if entry[0] == job_id: 163 return True 164 return False 165 166 def test_export_start(self): 167 # we can trigger export file creation 152 168 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 153 169 self.browser.open(self.datacenter_path) … … 156 172 self.browser.getLink("Export data").click() 157 173 self.browser.getControl(name="exporter").value = ['faculties'] 174 self.browser.getControl("Create CSV file").click() 175 self.assertEqual(self.browser.headers['Status'], '200 Ok') 176 return 177 178 def test_export_download(self): 179 # we can download a generated export result 180 self.test_export_start() 181 # while the export file is created, we get a reload button 182 # (or a loading bar if javascript is enabled)... 183 self.browser.getControl("Reload").click() 184 # ...which is displayed as long as the job is not finished. 185 # When the job is finished and we reload the page... 186 job_id = self.wait_for_export_job_completed() 187 try: 188 self.browser.getControl("Reload").click() 189 except LookupError: 190 # if the job completed very fast, we will get the download 191 # link immediately 192 pass 193 # ...we can download the result 158 194 self.browser.getControl("Download").click() 159 self.assertEqual(self.browser.headers['Status'], '200 Ok') 160 self.assertEqual(self.browser.headers['Content-Type'], 195 self.assertEqual(self.browser.headers['content-type'], 161 196 'text/csv; charset=UTF-8') 162 self.assert True ('WAeUP.KofaFaculties.csv' in163 self.browser.headers['content-disposition'])197 self.assertEqual(self.browser.headers['content-disposition'], 198 'attachment; filename="WAeUP.Kofa_faculties.csv') 164 199 self.assertEqual(self.browser.contents, 165 200 'code,title,title_prefix,users_with_local_roles\r\n' 166 201 'fac1,Unnamed Faculty,faculty,[]\r\n') 167 logfile = os.path.join( 168 self.app['datacenter'].storage, 'logs', 'datacenter.log') 169 logcontent = open(logfile).read() 170 self.assertTrue('zope.mgr - browser.pages.ExportCSVView - ' 171 'exported: faculties' in logcontent) 202 203 # after download, the job and the result file are removed 204 manager = getUtility(IJobManager) 205 result = manager.get(job_id) 206 self.assertEqual(result, None) 207 self.assertEqual(self.stored_in_datacenter(job_id), False) 208 #logfile = os.path.join( 209 # self.app['datacenter'].storage, 'logs', 'datacenter.log') 210 #logcontent = open(logfile).read() 211 #self.assertTrue('zope.mgr - browser.pages.ExportCSVView - ' 212 # 'exported: faculties' in logcontent) 213 return 214 215 def test_export_discard(self): 216 # we can discard a generated export result 217 self.test_export_start() 218 self.wait_for_export_job_completed() 219 self.browser.open(self.datacenter_path + '/@@export') 220 self.browser.getControl("Discard").click() 221 self.assertTrue('Discarded export result' in self.browser.contents) 172 222 return 173 223
Note: See TracChangeset for help on using the changeset viewer.