Ignore:
Timestamp:
30 Aug 2013, 04:18:04 (11 years ago)
Author:
Henrik Bettermann
Message:

Add browser tests.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students/reports
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_report.py

    r10563 r10564  
    154154
    155155    title = _('Level Report')
    156     grok.name('level_reports')
     156    grok.name('level_report')
    157157
    158158    def generate(self, site, faccode=None, depcode=None,
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_level_report.py

    r10563 r10564  
    3838        print "Sample level_report.pdf written to %s" % path
    3939        return
     40
     41class LevelReportUITests(StudentsFullSetup, FunctionalAsyncTestCase):
     42
     43    layer = FunctionalLayer
     44
     45    def wait_for_report_job_completed(self):
     46        # helper function waiting until the current export job is completed
     47        manager = getUtility(IJobManager)
     48        job_id = self.app['reports'].running_report_jobs[0][0]
     49        job = manager.get(job_id)
     50        wait_for_result(job)
     51        return job_id
     52
     53    def stored_in_reports(self, job_id):
     54        # tell whether job_id is stored in reports's running jobs list
     55        for entry in list(self.app['reports'].running_report_jobs):
     56            if entry[0] == job_id:
     57                return True
     58        return False
     59
     60    def trigger_report_creation(self):
     61        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     62        self.browser.open('http://localhost/app/reports')
     63        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     64        self.browser.getLink("Create new report").click()
     65        self.browser.getControl(name="generator").value = ['level_report']
     66        self.browser.getControl("Configure").click()
     67        self.browser.getControl(name="level").value = ['100']
     68        self.browser.getControl(name="session").value = ['2010']
     69        self.browser.getControl(name="faccode_depcode").value = ['fac1_dep1']
     70        self.browser.getControl("Create").click()
     71        return
     72
     73    def test_report_download(self):
     74        # We can download a generated report
     75        self.trigger_report_creation()
     76        # When the job is finished and we reload the page...
     77        job_id = self.wait_for_report_job_completed()
     78        self.browser.open('http://localhost/app/reports')
     79        # ... the pdf file can be downloaded ...
     80        self.browser.getControl("Download").click()
     81        self.assertEqual(self.browser.headers['content-type'],
     82                         'application/pdf')
     83        self.assertTrue(
     84            'filename="LevelReport_fac1_dep1_2010_100_' in
     85            self.browser.headers['content-disposition'])
     86        self.assertEqual(len(self.app['reports'].running_report_jobs), 1)
     87        job_id = self.app['reports'].running_report_jobs[0][0]
     88        # ... and discarded
     89        self.browser.open('http://localhost/app/reports')
     90        self.browser.getControl("Discard").click()
     91        self.assertEqual(len(self.app['reports'].running_report_jobs), 0)
     92        # Creation, downloading and discarding is logged
     93        logfile = os.path.join(
     94            self.app['datacenter'].storage, 'logs', 'main.log')
     95        logcontent = open(logfile).read()
     96        self.assertTrue(
     97            'INFO - zope.mgr - students.reports.level_report.LevelReportGeneratorPage - '
     98            'report %s created: Level Report (faculty=fac1, department=dep1, session=2010, level=100)'
     99            % job_id in logcontent
     100            )
     101        self.assertTrue(
     102            'INFO - zope.mgr - students.reports.level_report.LevelReportPDFView - '
     103            'report %s downloaded: LevelReport_fac1_dep1_2010_100_'
     104            % job_id in logcontent
     105            )
     106        self.assertTrue(
     107            'INFO - zope.mgr - browser.reports.ReportsContainerPage - '
     108            'report %s discarded' % job_id in logcontent
     109            )
     110        return
Note: See TracChangeset for help on using the changeset viewer.