- Timestamp:
- 2 Sep 2013, 06:42:16 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_level_results_presentation.py
r10574 r10576 6 6 from waeup.kofa.interfaces import IJobManager 7 7 from waeup.kofa.students.reports.level_results_presentation import ( 8 get_students )8 get_students, SessionResultsPresentation, ISessionResultsPresentation) 9 9 from waeup.kofa.students.tests.test_catalog import CatalogTestSetup 10 10 from waeup.kofa.students.tests.test_browser import StudentsFullSetup … … 14 14 from waeup.kofa.students.studylevel import StudentStudyLevel 15 15 16 class LevelReportTests(CatalogTestSetup):16 class SessionResultsPresentationTests(CatalogTestSetup): 17 17 18 18 layer = FunctionalLayer 19 20 def test_iface(self): 21 # ensure we fullfill interface contracts 22 obj = SessionResultsPresentation('fac1', 'dep1', 2010, 100) 23 verifyClass(ISessionResultsPresentation, SessionResultsPresentation) 24 verifyObject(ISessionResultsPresentation, obj) 25 return 19 26 20 27 def test_get_students(self): … … 48 55 return 49 56 57 def test_create_pdf(self): 58 report = SessionResultsPresentation('fac1', 'dep1', 2010, 100) 59 result = report.create_pdf() 60 self.assertTrue(result.startswith('%PDF-')) 61 path = os.path.join(samples_dir(), 'session_results_presentation.pdf') 62 open(path, 'wb').write(result) 63 print "Sample session_results_presentation.pdf written to %s" % path 64 return 65 66 class SessionResultsPresentationUITests(StudentsFullSetup, FunctionalAsyncTestCase): 67 68 layer = FunctionalLayer 69 70 def wait_for_report_job_completed(self): 71 # helper function waiting until the current export job is completed 72 manager = getUtility(IJobManager) 73 job_id = self.app['reports'].running_report_jobs[0][0] 74 job = manager.get(job_id) 75 wait_for_result(job) 76 return job_id 77 78 def stored_in_reports(self, job_id): 79 # tell whether job_id is stored in reports's running jobs list 80 for entry in list(self.app['reports'].running_report_jobs): 81 if entry[0] == job_id: 82 return True 83 return False 84 85 def trigger_report_creation(self): 86 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 87 self.browser.open('http://localhost/app/reports') 88 self.assertEqual(self.browser.headers['Status'], '200 Ok') 89 self.browser.getLink("Create new report").click() 90 self.browser.getControl(name="generator").value = ['session_results_presentation'] 91 self.browser.getControl("Configure").click() 92 self.browser.getControl(name="level").value = ['100'] 93 self.browser.getControl(name="session").value = ['2010'] 94 self.browser.getControl(name="faccode_depcode").value = ['fac1_dep1'] 95 self.browser.getControl("Create").click() 96 return 97 98 def test_report_download(self): 99 # We can download a generated report 100 self.trigger_report_creation() 101 # When the job is finished and we reload the page... 102 job_id = self.wait_for_report_job_completed() 103 self.browser.open('http://localhost/app/reports') 104 # ... the pdf file can be downloaded ... 105 self.browser.getControl("Download").click() 106 self.assertEqual(self.browser.headers['content-type'], 107 'application/pdf') 108 self.assertTrue( 109 'filename="SessionResultsPresentation_fac1_dep1_2010_100_' in 110 self.browser.headers['content-disposition']) 111 self.assertEqual(len(self.app['reports'].running_report_jobs), 1) 112 job_id = self.app['reports'].running_report_jobs[0][0] 113 # ... and discarded 114 self.browser.open('http://localhost/app/reports') 115 self.browser.getControl("Discard").click() 116 self.assertEqual(len(self.app['reports'].running_report_jobs), 0) 117 # Creation, downloading and discarding is logged 118 logfile = os.path.join( 119 self.app['datacenter'].storage, 'logs', 'main.log') 120 logcontent = open(logfile).read() 121 self.assertTrue( 122 'INFO - zope.mgr - students.reports.level_results_presentation.SessionResultsPresentationGeneratorPage - ' 123 'report %s created: Session Results Presentation (faculty=fac1, department=dep1, session=2010, level=100)' 124 % job_id in logcontent 125 ) 126 self.assertTrue( 127 'INFO - zope.mgr - students.reports.level_results_presentation.SessionResultsPresentationPDFView - ' 128 'report %s downloaded: SessionResultsPresentation_fac1_dep1_2010_100_' 129 % job_id in logcontent 130 ) 131 self.assertTrue( 132 'INFO - zope.mgr - browser.reports.ReportsContainerPage - ' 133 'report %s discarded' % job_id in logcontent 134 ) 135 return
Note: See TracChangeset for help on using the changeset viewer.