Ignore:
Timestamp:
21 Sep 2012, 11:21:05 (12 years ago)
Author:
uli
Message:

Merge changes from uli-async-update back into trunk.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/browser/tests
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py

    r9034 r9217  
    2121import shutil
    2222import tempfile
    23 import pytz
    24 from datetime import datetime, timedelta
    25 from StringIO import StringIO
    2623import os
    27 import grok
    28 from zope.event import notify
    29 from zope.component import createObject, queryUtility
     24from zc.async.testing import wait_for_result
     25from zope.component import createObject, getUtility
    3026from zope.component.hooks import setSite, clearSite
    31 from zope.catalog.interfaces import ICatalog
    3227from zope.security.interfaces import Unauthorized
    33 from zope.securitypolicy.interfaces import IPrincipalRoleManager
    3428from zope.testbrowser.testing import Browser
    35 from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    3629from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
    3730from waeup.kofa.app import University
     31from waeup.kofa.interfaces import IJobManager
     32from waeup.kofa.tests.test_async import FunctionalAsyncTestCase
    3833from waeup.kofa.university.faculty import Faculty
    3934from waeup.kofa.university.department import Department
     
    106101        shutil.rmtree(self.dc_root)
    107102
    108 
    109103class DataCenterUITests(UniversitySetup):
    110104    # Tests for DataCenter class views and pages
     
    149143        return
    150144
    151     def test_export(self):
     145
     146class DataCenterUIExportTests(UniversitySetup, FunctionalAsyncTestCase):
     147    # Tests for DataCenter class views and pages
     148
     149    layer = FunctionalLayer
     150
     151    def wait_for_export_job_completed(self):
     152        # helper function waiting until the current export job is completed
     153        manager = getUtility(IJobManager)
     154        job_id = self.app['datacenter'].running_exports[0][0]
     155        job = manager.get(job_id)
     156        wait_for_result(job)
     157        return job_id
     158
     159    def stored_in_datacenter(self, job_id):
     160        # tell whether job_id is stored in datacenter's running jobs list
     161        for entry in list(self.app['datacenter'].running_exports):
     162            if entry[0] == job_id:
     163                return True
     164        return False
     165
     166    def test_export_start(self):
     167        # we can trigger export file creation
    152168        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    153169        self.browser.open(self.datacenter_path)
     
    156172        self.browser.getLink("Export data").click()
    157173        self.browser.getControl(name="exporter").value = ['faculties']
     174        self.browser.getControl("Create CSV file").click()
     175        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     176        return
     177
     178    def test_export_download(self):
     179        # we can download a generated export result
     180        self.test_export_start()
     181        # while the export file is created, we get a reload button
     182        # (or a loading bar if javascript is enabled)...
     183        self.browser.getControl("Reload").click()
     184        # ...which is displayed as long as the job is not finished.
     185        # When the job is finished and we reload the page...
     186        job_id = self.wait_for_export_job_completed()
     187        try:
     188            self.browser.getControl("Reload").click()
     189        except LookupError:
     190            # if the job completed very fast, we will get the download
     191            # link immediately
     192            pass
     193        # ...we can download the result
    158194        self.browser.getControl("Download").click()
    159         self.assertEqual(self.browser.headers['Status'], '200 Ok')
    160         self.assertEqual(self.browser.headers['Content-Type'],
     195        self.assertEqual(self.browser.headers['content-type'],
    161196                         'text/csv; charset=UTF-8')
    162         self.assertTrue ('WAeUP.KofaFaculties.csv' in
    163             self.browser.headers['content-disposition'])
     197        self.assertEqual(self.browser.headers['content-disposition'],
     198                         'attachment; filename="WAeUP.Kofa_faculties.csv')
    164199        self.assertEqual(self.browser.contents,
    165200            'code,title,title_prefix,users_with_local_roles\r\n'
    166201            'fac1,Unnamed Faculty,faculty,[]\r\n')
    167         logfile = os.path.join(
    168             self.app['datacenter'].storage, 'logs', 'datacenter.log')
    169         logcontent = open(logfile).read()
    170         self.assertTrue('zope.mgr - browser.pages.ExportCSVView - '
    171                         'exported: faculties' in logcontent)
     202
     203        # after download, the job and the result file are removed
     204        manager = getUtility(IJobManager)
     205        result = manager.get(job_id)
     206        self.assertEqual(result, None)
     207        self.assertEqual(self.stored_in_datacenter(job_id), False)
     208        #logfile = os.path.join(
     209        #    self.app['datacenter'].storage, 'logs', 'datacenter.log')
     210        #logcontent = open(logfile).read()
     211        #self.assertTrue('zope.mgr - browser.pages.ExportCSVView - '
     212        #                'exported: faculties' in logcontent)
     213        return
     214
     215    def test_export_discard(self):
     216        # we can discard a generated export result
     217        self.test_export_start()
     218        self.wait_for_export_job_completed()
     219        self.browser.open(self.datacenter_path + '/@@export')
     220        self.browser.getControl("Discard").click()
     221        self.assertTrue('Discarded export result' in self.browser.contents)
    172222        return
    173223
Note: See TracChangeset for help on using the changeset viewer.