- Timestamp:
- 6 Sep 2012, 16:50:17 (12 years ago)
- Location:
- main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/tests
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/tests/test_browser.py
r8755 r9166 26 26 import os 27 27 import grok 28 from zc.async.testing import wait_for_result 28 29 from zope.event import notify 29 from zope.component import createObject, queryUtility 30 from zope.component import createObject, queryUtility, getUtility 30 31 from zope.component.hooks import setSite, clearSite 31 32 from zope.catalog.interfaces import ICatalog … … 36 37 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 37 38 from waeup.kofa.app import University 39 from waeup.kofa.interfaces import IJobManager 40 from waeup.kofa.tests.test_async import FunctionalAsyncTestCase 38 41 from waeup.kofa.university.faculty import Faculty 39 42 from waeup.kofa.university.department import Department 43 44 45 40 46 41 47 SAMPLE_FILE = os.path.join(os.path.dirname(__file__), 'test_file.csv') … … 106 112 shutil.rmtree(self.dc_root) 107 113 108 109 114 class DataCenterUITests(UniversitySetup): 110 115 # Tests for DataCenter class views and pages … … 149 154 return 150 155 151 def test_export(self): 156 157 class DataCenterUIExportTests(UniversitySetup, FunctionalAsyncTestCase): 158 # Tests for DataCenter class views and pages 159 160 layer = FunctionalLayer 161 162 def wait_for_export_job_completed(self): 163 # helper function waiting until the current export job is completed 164 manager = getUtility(IJobManager) 165 job_id = self.app['datacenter'].running_exports[0][0] 166 job = manager.get(job_id) 167 wait_for_result(job) 168 return job_id 169 170 def stored_in_datacenter(self, job_id): 171 # tell whether job_id is stored in datacenter's running jobs list 172 for entry in list(self.app['datacenter'].running_exports): 173 if entry[0] == job_id: 174 return True 175 return False 176 177 def test_export_start(self): 178 # we can trigger export file creation 152 179 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 153 180 self.browser.open(self.datacenter_path) … … 156 183 self.browser.getLink("Export CSV file").click() 157 184 self.browser.getControl(name="exporter").value = ['faculties'] 185 self.browser.getControl("Create CSV file").click() 186 self.assertEqual(self.browser.headers['Status'], '200 Ok') 187 return 188 189 def test_export_download(self): 190 # we can download a generated export result 191 self.test_export_start() 192 # while the export file is created, we get a reload button 193 # (or a loading bar if javascript is enabled)... 194 self.browser.getControl("Reload").click() 195 # ...which is displayed as long as the job is not finished. 196 # When the job is finished and we reload the page... 197 job_id = self.wait_for_export_job_completed() 198 try: 199 self.browser.getControl("Reload").click() 200 except LookupError: 201 # if the job completed very fast, we will get the download 202 # link immediately 203 pass 204 # ...we can download the result 158 205 self.browser.getControl("Download").click() 159 self.assertEqual(self.browser.headers['Status'], '200 Ok')160 206 self.assertEqual(self.browser.headers['Content-Type'], 161 207 'text/csv; charset=UTF-8') 162 208 self.assertEqual(self.browser.contents, 163 209 'code,title,title_prefix\r\nfac1,Unnamed Faculty,faculty\r\n') 164 logfile = os.path.join( 165 self.app['datacenter'].storage, 'logs', 'datacenter.log') 166 logcontent = open(logfile).read() 167 self.assertTrue('zope.mgr - browser.pages.ExportCSVView - ' 168 'exported: faculties' in logcontent) 169 return 210 211 # after download, the job and the result file are removed 212 manager = getUtility(IJobManager) 213 result = manager.get(job_id) 214 self.assertEqual(result, None) 215 self.assertEqual(self.stored_in_datacenter(job_id), False) 216 #logfile = os.path.join( 217 # self.app['datacenter'].storage, 'logs', 'datacenter.log') 218 #logcontent = open(logfile).read() 219 #self.assertTrue('zope.mgr - browser.pages.ExportCSVView - ' 220 # 'exported: faculties' in logcontent) 221 return 222 223 def test_export_discard(self): 224 # we can discard a generated export result 225 self.test_export_start() 226 self.wait_for_export_job_completed() 227 self.browser.open(self.datacenter_path + '/@@export') 228 self.browser.getControl("Discard").click() 229 self.assertTrue('Discarded export result' in self.browser.contents) 230 return
Note: See TracChangeset for help on using the changeset viewer.