Ignore:
Timestamp:
19 Jul 2017, 19:16:36 (7 years ago)
Author:
Henrik Bettermann
Message:

Use same application module setup as for kwarapoly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.dspg/trunk/src/kofacustom/dspg/applicants/tests/test_browser.py

    r14716 r14721  
    1919Test the applicant-related UI components.
    2020"""
     21import shutil
     22import tempfile
     23import datetime
     24import pytz
    2125import os
    22 import datetime
     26from zope.component.hooks import setSite, clearSite
    2327from zope.component import createObject, getUtility
    2428from zope.catalog.interfaces import ICatalog
    2529from zope.intid.interfaces import IIntIds
    26 from hurry.workflow.interfaces import IWorkflowState
     30from zope.testbrowser.testing import Browser
    2731from kofacustom.dspg.testing import FunctionalLayer
    28 from waeup.kofa.browser.tests.test_pdf import samples_dir
    29 from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
     32from waeup.kofa.app import University
     33from waeup.kofa.university.faculty import Faculty
     34from waeup.kofa.university.department import Department
     35from waeup.kofa.testing import FunctionalTestCase
    3036from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
    31 from kofacustom.dspg.applicants.export import CustomApplicantExporter
    32 from kofacustom.dspg.applicants.batching import CustomApplicantProcessor
     37from waeup.kofa.applicants.container import ApplicantsContainer
    3338
    34 class CustomApplicantUITests(ApplicantsFullSetup):
    35     # Tests for uploading/browsing the passport image of appplicants
     39session = datetime.datetime.now().year - 2
     40ndftcontainer_name = u'ndft%s' % session
    3641
     42class ApplicantUITest(FunctionalTestCase):
     43    """Perform some browser tests.
     44    """
    3745    layer = FunctionalLayer
     46
     47    def setUp(self):
     48        super(ApplicantUITest, self).setUp()
     49        # Setup a sample site for each test
     50        app = University()
     51        self.dc_root = tempfile.mkdtemp()
     52        app['datacenter'].setStoragePath(self.dc_root)
     53
     54        # Prepopulate the ZODB...
     55        self.getRootFolder()['app'] = app
     56        # we add the site immediately after creation to the
     57        # ZODB. Catalogs and other local utilities are not setup
     58        # before that step.
     59        self.app = self.getRootFolder()['app']
     60        # Set site here. Some of the following setup code might need
     61        # to access grok.getSite() and should get our new app then
     62        setSite(app)
     63
     64        # Add ndft applicants container
     65        self.ndftcontainer = ApplicantsContainer()
     66        self.ndftcontainer.mode = 'create'
     67        self.ndftcontainer.code = ndftcontainer_name
     68        self.ndftcontainer.prefix = u'ndft'
     69        self.ndftcontainer.application_category = u'ndft'
     70        self.ndftcontainer.year = session
     71        self.ndftcontainer.application_fee = 300.0
     72        #self.ndftcontainer.title = u'This is the %s container' % ndftcontainer_name
     73        self.app['applicants'][ndftcontainer_name] = self.ndftcontainer
     74
     75        delta = datetime.timedelta(days=10)
     76        self.ndftcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
     77        self.ndftcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
     78
     79        # Populate university
     80        self.certificate = createObject('waeup.Certificate')
     81        self.certificate.code = 'CERT1'
     82        self.certificate.application_category = 'ndft'
     83        self.certificate.start_level = 100
     84        self.certificate.end_level = 500
     85        self.certificate.study_mode = u'nce_ft'
     86        self.app['faculties']['fac1'] = Faculty()
     87        self.app['faculties']['fac1']['dep1'] = Department()
     88        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     89            self.certificate)
     90
     91        # Add (customized) applicants
     92        ndftapplicant = createObject(u'waeup.Applicant')
     93        ndftapplicant.firstname = u'Anna'
     94        ndftapplicant.lastname = u'Post'
     95        self.app['applicants'][ndftcontainer_name].addApplicant(ndftapplicant)
     96        self.ndftapplication_number = ndftapplicant.application_number
     97        self.ndftapplicant = self.app['applicants'][ndftcontainer_name][
     98            self.ndftapplication_number]
     99        self.ndftapplicant_path = ('http://localhost/app/applicants/%s/%s'
     100            % (ndftcontainer_name, self.ndftapplication_number))
     101
     102        self.browser = Browser()
     103        self.browser.handleErrors = False
     104
     105    def tearDown(self):
     106        super(ApplicantUITest, self).tearDown()
     107        shutil.rmtree(self.dc_root)
     108        clearSite()
     109        return
     110
     111    def fill_correct_values(self):
     112        self.browser.getControl(name="form.reg_number").value = '1234'
     113        self.browser.getControl(name="form.firstname").value = 'John'
     114        self.browser.getControl(name="form.lastname").value = 'Tester'
     115        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
     116        self.browser.getControl(name="form.lga").value = ['foreigner']
     117        #self.browser.getControl(name="form.nationality").value = ['NG']
     118        #self.browser.getControl(name="form.sex").value = ['m']
     119        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
     120
     121    def test_manage_and_view_applicant(self):
     122        # Managers can manage ndft applicants.
     123        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     124        self.browser.open(self.ndftapplicant_path)
     125        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     126        self.assertTrue("'O' Level" in self.browser.contents)
     127        self.assertFalse("Higher" in self.browser.contents)
     128        self.browser.open(self.ndftapplicant_path + '/manage')
     129        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     130        self.assertTrue("'O' Level" in self.browser.contents)
     131        self.assertTrue("Higher" in self.browser.contents)
     132        self.browser.open(self.ndftapplicant_path + '/edit')
     133        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     134        self.assertTrue("'O' Level" in self.browser.contents)
     135        self.assertFalse("Higher" in self.browser.contents)
     136        self.browser.open(self.ndftapplicant_path + '/application_slip.pdf')
     137        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     138        # Now we turn the ndft applicant into an hndft applicant.
     139        self.ndftapplicant.applicant_id = u'hndft_anything'
     140        self.browser.open(self.ndftapplicant_path)
     141        self.assertTrue("Higher" in self.browser.contents)
     142        self.assertTrue("'O' Level" in self.browser.contents)
     143        self.browser.open(self.ndftapplicant_path + '/edit')
     144        self.assertTrue("Higher" in self.browser.contents)
     145        self.assertTrue("'O' Level" in self.browser.contents)
     146
     147        self.browser.open(self.ndftapplicant_path + '/manage')
     148        # Manager can fill and save the form
     149        self.fill_correct_values()
     150        self.browser.getControl("Save").click()
     151        self.assertMatches('...Form has been saved...', self.browser.contents)
     152        return
    38153
    39154class ApplicantExporterTest(ApplicantImportExportSetup):
     
    69184        applicant.password = 'any password'
    70185        return applicant
    71 
    72 class ApplicantsContainerUITests(ApplicantsFullSetup):
    73     # Tests for ApplicantsContainer class views and pages
    74 
    75     layer = FunctionalLayer
    76 
    77     def test_application_slip(self):
    78         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    79         self.slip_path = self.view_path + '/application_slip.pdf'
    80         self.browser.open(self.manage_path)
    81         self.assertEqual(self.browser.headers['Status'], '200 Ok')
    82         self.fill_correct_values()
    83         self.browser.getControl("Save").click()
    84         IWorkflowState(self.applicant).setState('submitted')
    85         self.browser.open(self.manage_path)
    86         self.browser.getLink("Download application slip").click()
    87         self.assertEqual(self.browser.headers['Status'], '200 Ok')
    88         self.assertEqual(self.browser.headers['Content-Type'],
    89                          'application/pdf')
    90         path = os.path.join(samples_dir(), 'application_slip.pdf')
    91         open(path, 'wb').write(self.browser.contents)
    92         print "Sample application_slip.pdf written to %s" % path
Note: See TracChangeset for help on using the changeset viewer.