Changeset 9639


Ignore:
Timestamp:
15 Nov 2012, 15:38:25 (12 years ago)
Author:
uli
Message:

Provide a reduced set of stati in report jobs which are better suited for frontends.

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

Legend:

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

    r9638 r9639  
    3232from waeup.kofa.utils.helpers import now
    3333
     34#: A status map that reflects the really interesting types of status
     35#: for reports.
     36#:
     37#: For reports we want to know whether a job was finished
     38#: and/or whether it failed. All the other possible states ('new',
     39#: etc.) are not really interesting in that regard.
     40STATUS_MAP = {
     41    'unknown': _('unknown'),
     42    'running': _('running'),
     43    'finished': _('finished'),
     44    'failed': _('FAILED'),
     45    }
     46
    3447class IReport(Interface):
    3548    """A report.
     
    8497        title = u"""Textual representation of arguments and keywords.""",
    8598        default = u"",
     99        )
     100
     101    report_status = schema.TextLine(
     102        title = u"""Translated status string.""",
     103        default = STATUS_MAP['unknown'],
    86104        )
    87105
     
    299317            return True
    300318        return False
     319
     320    @property
     321    def report_status(self):
     322        """The status of a report as translated string.
     323        """
     324        if not self.finished:
     325            return STATUS_MAP['running']
     326        if self.failed:
     327            return STATUS_MAP['failed']
     328        return STATUS_MAP['finished']
    301329
    302330    @property
     
    327355        return name + ' ' + str_repr
    328356
    329 
    330357@implementer(IReportJobContainer)
    331358class ReportJobContainer(object):
     
    441468            manager = getUtility(IJobManager)
    442469            job = manager.get(job_id)
    443             status = JOB_STATUS_MAP.get(job.status, job.status)[1]
     470            status = job.report_status
    444471            discardable = job.finished
    445472            downloadable = job.finished and not job.failed
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_reports.py

    r9638 r9639  
    256256        return
    257257
     258    def test_report_status(self):
     259        # We can get a report status apart from the job status
     260        job = AsyncReportJob(self.root_folder, 'report1')
     261        self.assertEqual(job.report_status, u'running')
     262        return
     263
     264    def test_report_status_failed(self):
     265        # A failed job is reflected in report_status
     266        job = AsyncReportJob(self.root_folder, None) # no report generator
     267        setSite(self.root_folder)
     268        self.assertTrue(job.failed is None)
     269        manager = getUtility(IJobManager)
     270        manager.put(job)
     271        wait_for_result(job)
     272        self.assertEqual(job.report_status, u'FAILED')
     273        return
     274
     275    def test_report_status_finished(self):
     276        # A finished report is reflected in report_status
     277        job = AsyncReportJob(self.root_folder, 'report1')
     278        setSite(self.root_folder)
     279        manager = getUtility(IJobManager)
     280        manager.put(job)
     281        wait_for_result(job)
     282        self.assertEqual(job.report_status, u'finished')
     283        return
     284
    258285class FakeJobWithResult(FakeJob):
    259286
     
    368395        self.assertEqual(
    369396            result,
    370             [('2', 'Report 1 ()', u'new', False, False),]
     397            [('2', 'Report 1 ()', u'running', False, False),]
    371398            )
    372399        return
Note: See TracChangeset for help on using the changeset viewer.