Changeset 13950 for main


Ignore:
Timestamp:
17 Jun 2016, 10:02:02 (8 years ago)
Author:
Henrik Bettermann
Message:

Start ApplicantExporter and ApplicantPaymentExporter at the same
time when calling ExportJobContainerJobStart.

Location:
main/waeup.kofa/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r13949 r13950  
    441.4.2.dev0 (unreleased)
    55=======================
     6
     7* Start `ApplicantExporter` and `ApplicantPaymentExporter` at the same
     8  time when calling `ExportJobContainerJobStart`.
    69
    710* Add `ApplicantPaymentExporter`.
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r13886 r13950  
    2121import sys
    2222import grok
     23import transaction
    2324from datetime import datetime, date
    2425from zope.event import notify
     
    14231424        return
    14241425
    1425 class ExportJobContainerJobStart(KofaPage):
    1426     """Page that starts an applicants export job.
    1427 
     1426class ExportJobContainerJobStart(UtilityView, grok.View):
     1427    """View that starts two export jobs, one for applicants and a second
     1428    one for applicant payments.
    14281429    """
    14291430    grok.context(VirtualApplicantsExportJobContainer)
     
    14391440            self.entries = doll_up(self, user=None)
    14401441            return
     1442
     1443        ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
     1444        container_code = self.context.__parent__.code
     1445        # Start first exporter
    14411446        exporter = 'applicants'
    1442         container_code = self.context.__parent__.code
    14431447        job_id = self.context.start_export_job(exporter,
    14441448                                      self.request.principal.id,
    14451449                                      container=container_code)
    1446 
    1447         ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
    14481450        self.context.logger.info(
    14491451            '%s - exported: %s (%s), job_id=%s'
    14501452            % (ob_class, exporter, container_code, job_id))
    1451         self.flash(_('Export started.'))
     1453        # Commit transaction so that job is stored in the ZODB
     1454        transaction.commit()
     1455        # Start second exporter
     1456        exporter = 'applicantpayments'
     1457        job_id = self.context.start_export_job(exporter,
     1458                                      self.request.principal.id,
     1459                                      container=container_code)
     1460        self.context.logger.info(
     1461            '%s - exported: %s (%s), job_id=%s'
     1462            % (ob_class, exporter, container_code, job_id))
     1463
     1464        self.flash(_('Exports started.'))
    14521465        self.redirect(self.url(self.context))
    14531466        return
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser_templates/exportjobsindex.pt

    r11254 r13950  
    5555<form method="POST" i18n:domain="waeup.kofa">
    5656  <input class="btn btn-primary" type="submit" name="CREATE"
    57          value="Start new export"
     57         value="Start new exports"
    5858          />
    5959</form>
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py

    r13886 r13950  
    14471447    layer = FunctionalLayer
    14481448
    1449     def wait_for_export_job_completed(self):
     1449    def wait_for_export_jobs_completed(self):
    14501450        # helper function waiting until the current export job is completed
    14511451        manager = getUtility(IJobManager)
    1452         job_id = self.app['datacenter'].running_exports[0][0]
    1453         job = manager.get(job_id)
    1454         wait_for_result(job)
    1455         return job_id
     1452        job_ids = [i[0] for i in self.app['datacenter'].running_exports]
     1453        jobs = [manager.get(job_id) for job_id in job_ids]
     1454        for job in jobs:
     1455            wait_for_result(job)
     1456        return job_ids
    14561457
    14571458    def test_applicants_in_container_export(self):
     
    14601461        self.browser.open(container_path)
    14611462        self.browser.getLink("Export applicants").click()
    1462         self.browser.getControl("Start new export").click()
    1463 
    1464         # When the job is finished and we reload the page...
    1465         job_id = self.wait_for_export_job_completed()
     1463        self.browser.getControl("Start new exports").click()
     1464        job_ids = self.wait_for_export_jobs_completed()
     1465        # Two exports were created
     1466        self.assertEqual(len(self.app['datacenter'].running_exports), 2)
     1467       # When the jobs are finished and we reload the page...
    14661468        self.browser.open(container_path + '/exports')
    1467         # ... the csv file can be downloaded ...
    1468         self.browser.getLink("Download").click()
     1469        # ... the both csv files can be downloaded ...
     1470        self.browser.getLink("Download", index=0).click()
    14691471        self.assertEqual(self.browser.headers['content-type'],
    14701472            'text/csv; charset=UTF-8')
    14711473        self.assertTrue(
    1472             'filename="WAeUP.Kofa_applicants_%s.csv' % job_id in
     1474            'filename="WAeUP.Kofa_applicants_%s.csv' % job_ids[0] in
    14731475            self.browser.headers['content-disposition'])
    1474         self.assertEqual(len(self.app['datacenter'].running_exports), 1)
    1475         job_id = self.app['datacenter'].running_exports[0][0]
     1476        self.browser.open(container_path + '/exports')
     1477        self.browser.getLink("Download", index=1).click()
     1478        self.assertEqual(self.browser.headers['content-type'],
     1479            'text/csv; charset=UTF-8')
     1480        self.assertTrue(
     1481            'filename="WAeUP.Kofa_applicantpayments_%s.csv' % job_ids[1] in
     1482            self.browser.headers['content-disposition'])
    14761483        # ... and discarded
    14771484        self.browser.open(container_path + '/exports')
     1485        self.browser.getControl("Discard", index=0).click()
     1486        self.assertEqual(len(self.app['datacenter'].running_exports), 1)
    14781487        self.browser.getControl("Discard").click()
    14791488        self.assertEqual(len(self.app['datacenter'].running_exports), 0)
    1480         # Creation, downloading and discarding is logged
     1489        # Creation, downloading and discarding are logged
    14811490        logfile = os.path.join(
    14821491            self.app['datacenter'].storage, 'logs', 'datacenter.log')
     
    14851494            'zope.mgr - applicants.browser.ExportJobContainerJobStart - '
    14861495            'exported: applicants (%s), job_id=%s'
    1487             % (container_name_1, job_id) in logcontent
     1496            % (container_name_1, job_ids[0]) in logcontent
    14881497            )
    14891498        self.assertTrue(
    14901499            'zope.mgr - applicants.browser.ExportJobContainerDownload '
    14911500            '- downloaded: WAeUP.Kofa_applicants_%s.csv, job_id=%s'
    1492             % (job_id, job_id) in logcontent
     1501            % (job_ids[0], job_ids[0]) in logcontent
    14931502            )
    14941503        self.assertTrue(
    14951504            'zope.mgr - applicants.browser.ExportJobContainerOverview '
    1496             '- discarded: job_id=%s' % job_id in logcontent
     1505            '- discarded: job_id=%s' % job_ids[0] in logcontent
    14971506            )
     1507        self.assertTrue(
     1508            'zope.mgr - applicants.browser.ExportJobContainerJobStart - '
     1509            'exported: applicantpayments (%s), job_id=%s'
     1510            % (container_name_1, job_ids[1]) in logcontent
     1511            )
     1512        self.assertTrue(
     1513            'zope.mgr - applicants.browser.ExportJobContainerDownload '
     1514            '- downloaded: WAeUP.Kofa_applicantpayments_%s.csv, job_id=%s'
     1515            % (job_ids[1], job_ids[1]) in logcontent
     1516            )
     1517        self.assertTrue(
     1518            'zope.mgr - applicants.browser.ExportJobContainerOverview '
     1519            '- discarded: job_id=%s' % job_ids[1] in logcontent
     1520            )
Note: See TracChangeset for help on using the changeset viewer.