Changeset 9678 for main/waeup.kofa/trunk/src/waeup/kofa/students/tests
- Timestamp:
- 18 Nov 2012, 09:19:35 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_reports.py
r9673 r9678 1 1 # Tests for student related reports 2 import os 3 from zc.async.testing import wait_for_result 2 4 from zope.interface.verify import verifyClass, verifyObject 5 from zope.component import getUtility 6 from waeup.kofa.interfaces import IJobManager 3 7 from waeup.kofa.students.reports import ( 4 8 get_students_by, StudentsReport, IStudentsReport) 5 9 from waeup.kofa.students.tests.test_catalog import CatalogTestSetup 10 from waeup.kofa.students.tests.test_browser import StudentsFullSetup 6 11 from waeup.kofa.testing import FunctionalLayer 12 from waeup.kofa.tests.test_async import FunctionalAsyncTestCase 7 13 8 14 class StudentsReportTests(CatalogTestSetup): … … 66 72 self.assertTrue(result.startswith('%PDF-')) 67 73 return 74 75 class StudentsReportUITests(StudentsFullSetup, FunctionalAsyncTestCase): 76 77 layer = FunctionalLayer 78 79 def wait_for_report_job_completed(self): 80 # helper function waiting until the current export job is completed 81 manager = getUtility(IJobManager) 82 job_id = self.app['reports'].running_report_jobs[0][0] 83 job = manager.get(job_id) 84 wait_for_result(job) 85 return job_id 86 87 def stored_in_reports(self, job_id): 88 # tell whether job_id is stored in reports's running jobs list 89 for entry in list(self.app['reports'].running_report_jobs): 90 if entry[0] == job_id: 91 return True 92 return False 93 94 def trigger_report_creation(self): 95 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 96 self.browser.open('http://localhost/app/reports') 97 self.assertEqual(self.browser.headers['Status'], '200 Ok') 98 self.browser.getLink("Create new report").click() 99 self.browser.getControl(name="generator").value = ['students_by'] 100 self.browser.getControl("Configure").click() 101 self.browser.getControl(name="mode").value = ['All'] 102 self.browser.getControl(name="session").value = ['2004'] 103 self.browser.getControl("Create").click() 104 return 105 106 def test_report_download(self): 107 # We can download a generated report 108 self.trigger_report_creation() 109 # When the job is finished and we reload the page... 110 job_id = self.wait_for_report_job_completed() 111 self.browser.open('http://localhost/app/reports') 112 # ... the pdf file can be downloaded ... 113 self.browser.getControl("Download").click() 114 self.assertEqual(self.browser.headers['content-type'], 115 'application/pdf') 116 self.assertTrue( 117 'filename="StudentsReport_2004_2005_All_' in 118 self.browser.headers['content-disposition']) 119 self.assertEqual(len(self.app['reports'].running_report_jobs), 1) 120 job_id = self.app['reports'].running_report_jobs[0][0] 121 # ... and discarded 122 self.browser.open('http://localhost/app/reports') 123 self.browser.getControl("Discard").click() 124 self.assertEqual(len(self.app['reports'].running_report_jobs), 0) 125 # Creation, downloading and discarding is logged 126 logfile = os.path.join( 127 self.app['datacenter'].storage, 'logs', 'main.log') 128 logcontent = open(logfile).read() 129 self.assertTrue( 130 'INFO - zope.mgr - students.reports.StudentsReportGeneratorPage - ' 131 'created: Students (session=2004, mode=All)' in logcontent 132 ) 133 self.assertTrue( 134 'INFO - zope.mgr - students.reports.StudentsReportPDFView - ' 135 'downloaded: StudentsReport_2004_2005_All_' in logcontent 136 ) 137 self.assertTrue( 138 'INFO - zope.mgr - browser.reports.ReportsContainerPage - ' 139 'discarded: %s' % job_id in logcontent 140 ) 141 return
Note: See TracChangeset for help on using the changeset viewer.