Ignore:
Timestamp:
6 Sep 2012, 16:50:17 (12 years ago)
Author:
uli
Message:

All remaining changes from last weeks. Sorry for the mess.

Location:
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/tests
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/browser/tests/test_browser.py

    r8755 r9166  
    2626import os
    2727import grok
     28from zc.async.testing import wait_for_result
    2829from zope.event import notify
    29 from zope.component import createObject, queryUtility
     30from zope.component import createObject, queryUtility, getUtility
    3031from zope.component.hooks import setSite, clearSite
    3132from zope.catalog.interfaces import ICatalog
     
    3637from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
    3738from waeup.kofa.app import University
     39from waeup.kofa.interfaces import IJobManager
     40from waeup.kofa.tests.test_async import FunctionalAsyncTestCase
    3841from waeup.kofa.university.faculty import Faculty
    3942from waeup.kofa.university.department import Department
     43
     44
     45
    4046
    4147SAMPLE_FILE = os.path.join(os.path.dirname(__file__), 'test_file.csv')
     
    106112        shutil.rmtree(self.dc_root)
    107113
    108 
    109114class DataCenterUITests(UniversitySetup):
    110115    # Tests for DataCenter class views and pages
     
    149154        return
    150155
    151     def test_export(self):
     156
     157class DataCenterUIExportTests(UniversitySetup, FunctionalAsyncTestCase):
     158    # Tests for DataCenter class views and pages
     159
     160    layer = FunctionalLayer
     161
     162    def wait_for_export_job_completed(self):
     163        # helper function waiting until the current export job is completed
     164        manager = getUtility(IJobManager)
     165        job_id = self.app['datacenter'].running_exports[0][0]
     166        job = manager.get(job_id)
     167        wait_for_result(job)
     168        return job_id
     169
     170    def stored_in_datacenter(self, job_id):
     171        # tell whether job_id is stored in datacenter's running jobs list
     172        for entry in list(self.app['datacenter'].running_exports):
     173            if entry[0] == job_id:
     174                return True
     175        return False
     176
     177    def test_export_start(self):
     178        # we can trigger export file creation
    152179        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    153180        self.browser.open(self.datacenter_path)
     
    156183        self.browser.getLink("Export CSV file").click()
    157184        self.browser.getControl(name="exporter").value = ['faculties']
     185        self.browser.getControl("Create CSV file").click()
     186        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     187        return
     188
     189    def test_export_download(self):
     190        # we can download a generated export result
     191        self.test_export_start()
     192        # while the export file is created, we get a reload button
     193        # (or a loading bar if javascript is enabled)...
     194        self.browser.getControl("Reload").click()
     195        # ...which is displayed as long as the job is not finished.
     196        # When the job is finished and we reload the page...
     197        job_id = self.wait_for_export_job_completed()
     198        try:
     199            self.browser.getControl("Reload").click()
     200        except LookupError:
     201            # if the job completed very fast, we will get the download
     202            # link immediately
     203            pass
     204        # ...we can download the result
    158205        self.browser.getControl("Download").click()
    159         self.assertEqual(self.browser.headers['Status'], '200 Ok')
    160206        self.assertEqual(self.browser.headers['Content-Type'],
    161207                         'text/csv; charset=UTF-8')
    162208        self.assertEqual(self.browser.contents,
    163209            'code,title,title_prefix\r\nfac1,Unnamed Faculty,faculty\r\n')
    164         logfile = os.path.join(
    165             self.app['datacenter'].storage, 'logs', 'datacenter.log')
    166         logcontent = open(logfile).read()
    167         self.assertTrue('zope.mgr - browser.pages.ExportCSVView - '
    168                         'exported: faculties' in logcontent)
    169         return
     210
     211        # after download, the job and the result file are removed
     212        manager = getUtility(IJobManager)
     213        result = manager.get(job_id)
     214        self.assertEqual(result, None)
     215        self.assertEqual(self.stored_in_datacenter(job_id), False)
     216        #logfile = os.path.join(
     217        #    self.app['datacenter'].storage, 'logs', 'datacenter.log')
     218        #logcontent = open(logfile).read()
     219        #self.assertTrue('zope.mgr - browser.pages.ExportCSVView - '
     220        #                'exported: faculties' in logcontent)
     221        return
     222
     223    def test_export_discard(self):
     224        # we can discard a generated export result
     225        self.test_export_start()
     226        self.wait_for_export_job_completed()
     227        self.browser.open(self.datacenter_path + '/@@export')
     228        self.browser.getControl("Discard").click()
     229        self.assertTrue('Discarded export result' in self.browser.contents)
     230        return
Note: See TracChangeset for help on using the changeset viewer.