Ignore:
Timestamp:
17 Nov 2014, 06:46:52 (10 years ago)
Author:
Henrik Bettermann
Message:

Add exporter tests.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r11977 r11978  
    693693                        '123 (K1000000) - new@yy.zz' in logcontent)
    694694        return
     695
     696class CustomerDataExportTests(CustomersFullSetup, FunctionalAsyncTestCase):
     697    # Tests for CustomersContainer class views and pages
     698
     699    layer = FunctionalLayer
     700
     701    def wait_for_export_job_completed(self):
     702        # helper function waiting until the current export job is completed
     703        manager = getUtility(IJobManager)
     704        job_id = self.app['datacenter'].running_exports[0][0]
     705        job = manager.get(job_id)
     706        wait_for_result(job)
     707        return job_id
     708
     709    def test_datacenter_export(self):
     710        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     711        self.browser.open('http://localhost/app/datacenter/@@export')
     712        self.browser.getControl(name="exporter").value = ['customers']
     713        self.browser.getControl("Create CSV file").click()
     714
     715        # When the job is finished and we reload the page...
     716        job_id = self.wait_for_export_job_completed()
     717        # ... the csv file can be downloaded ...
     718        self.browser.open('http://localhost/app/datacenter/@@export')
     719        self.browser.getLink("Download").click()
     720        self.assertEqual(self.browser.headers['content-type'],
     721            'text/csv; charset=UTF-8')
     722        self.assertTrue(
     723            'filename="WAeUP.Ikoba_customers_%s.csv' % job_id in
     724            self.browser.headers['content-disposition'])
     725        self.assertEqual(len(self.app['datacenter'].running_exports), 1)
     726        job_id = self.app['datacenter'].running_exports[0][0]
     727        # ... and discarded
     728        self.browser.open('http://localhost/app/datacenter/@@export')
     729        self.browser.getControl("Discard").click()
     730        self.assertEqual(len(self.app['datacenter'].running_exports), 0)
     731        # Creation, downloading and discarding is logged
     732        logfile = os.path.join(
     733            self.app['datacenter'].storage, 'logs', 'datacenter.log')
     734        logcontent = open(logfile).read()
     735        self.assertTrue(
     736            'zope.mgr - browser.pages.ExportCSVPage - exported: '
     737            'customers, job_id=%s'
     738            % job_id in logcontent
     739            )
     740        self.assertTrue(
     741            'zope.mgr - browser.pages.ExportCSVView - downloaded: '
     742            'WAeUP.Ikoba_customers_%s.csv, job_id=%s'
     743            % (job_id, job_id) in logcontent
     744            )
     745        self.assertTrue(
     746            'zope.mgr - browser.pages.ExportCSVPage - discarded: '
     747            'job_id=%s' % job_id in logcontent
     748            )
Note: See TracChangeset for help on using the changeset viewer.