| 1 | ## $Id: test_browser.py 10941 2014-01-18 06:28:34Z henrik $ |
|---|
| 2 | ## |
|---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
|---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
|---|
| 5 | ## it under the terms of the GNU General Public License as published by |
|---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | ## (at your option) any later version. |
|---|
| 8 | ## |
|---|
| 9 | ## This program is distributed in the hope that it will be useful, |
|---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | ## GNU General Public License for more details. |
|---|
| 13 | ## |
|---|
| 14 | ## You should have received a copy of the GNU General Public License |
|---|
| 15 | ## along with this program; if not, write to the Free Software |
|---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 | ## |
|---|
| 18 | import shutil |
|---|
| 19 | import tempfile |
|---|
| 20 | import datetime |
|---|
| 21 | import pytz |
|---|
| 22 | from zope.component.hooks import setSite, clearSite |
|---|
| 23 | from zope.component import createObject |
|---|
| 24 | from zope.testbrowser.testing import Browser |
|---|
| 25 | from waeup.kofa.app import University |
|---|
| 26 | from waeup.kofa.university.faculty import Faculty |
|---|
| 27 | from waeup.kofa.university.department import Department |
|---|
| 28 | from waeup.kofa.testing import FunctionalTestCase |
|---|
| 29 | from waeup.kofa.applicants.container import ApplicantsContainer |
|---|
| 30 | from waeup.kwarapoly.testing import FunctionalLayer |
|---|
| 31 | |
|---|
| 32 | session = datetime.datetime.now().year - 2 |
|---|
| 33 | ndftcontainer_name = u'ndft%s' % session |
|---|
| 34 | |
|---|
| 35 | class ApplicantUITest(FunctionalTestCase): |
|---|
| 36 | """Perform some browser tests. |
|---|
| 37 | """ |
|---|
| 38 | layer = FunctionalLayer |
|---|
| 39 | |
|---|
| 40 | def setUp(self): |
|---|
| 41 | super(ApplicantUITest, self).setUp() |
|---|
| 42 | # Setup a sample site for each test |
|---|
| 43 | app = University() |
|---|
| 44 | self.dc_root = tempfile.mkdtemp() |
|---|
| 45 | app['datacenter'].setStoragePath(self.dc_root) |
|---|
| 46 | |
|---|
| 47 | # Prepopulate the ZODB... |
|---|
| 48 | self.getRootFolder()['app'] = app |
|---|
| 49 | # we add the site immediately after creation to the |
|---|
| 50 | # ZODB. Catalogs and other local utilities are not setup |
|---|
| 51 | # before that step. |
|---|
| 52 | self.app = self.getRootFolder()['app'] |
|---|
| 53 | # Set site here. Some of the following setup code might need |
|---|
| 54 | # to access grok.getSite() and should get our new app then |
|---|
| 55 | setSite(app) |
|---|
| 56 | |
|---|
| 57 | # Add ndft applicants container |
|---|
| 58 | self.ndftcontainer = ApplicantsContainer() |
|---|
| 59 | self.ndftcontainer.mode = 'create' |
|---|
| 60 | self.ndftcontainer.code = ndftcontainer_name |
|---|
| 61 | self.ndftcontainer.prefix = u'ndft' |
|---|
| 62 | self.ndftcontainer.application_category = u'ndft' |
|---|
| 63 | self.ndftcontainer.year = session |
|---|
| 64 | self.ndftcontainer.application_fee = 300.0 |
|---|
| 65 | #self.ndftcontainer.title = u'This is the %s container' % ndftcontainer_name |
|---|
| 66 | self.app['applicants'][ndftcontainer_name] = self.ndftcontainer |
|---|
| 67 | |
|---|
| 68 | delta = datetime.timedelta(days=10) |
|---|
| 69 | self.ndftcontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
|---|
| 70 | self.ndftcontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
|---|
| 71 | |
|---|
| 72 | # Populate university |
|---|
| 73 | self.certificate = createObject('waeup.Certificate') |
|---|
| 74 | self.certificate.code = 'CERT1' |
|---|
| 75 | self.certificate.application_category = 'ndft' |
|---|
| 76 | self.certificate.start_level = 100 |
|---|
| 77 | self.certificate.end_level = 500 |
|---|
| 78 | self.certificate.study_mode = u'nce_ft' |
|---|
| 79 | self.app['faculties']['fac1'] = Faculty() |
|---|
| 80 | self.app['faculties']['fac1']['dep1'] = Department() |
|---|
| 81 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
|---|
| 82 | self.certificate) |
|---|
| 83 | |
|---|
| 84 | # Add (customized) applicants |
|---|
| 85 | ndftapplicant = createObject(u'waeup.Applicant') |
|---|
| 86 | ndftapplicant.firstname = u'Anna' |
|---|
| 87 | ndftapplicant.lastname = u'Post' |
|---|
| 88 | self.app['applicants'][ndftcontainer_name].addApplicant(ndftapplicant) |
|---|
| 89 | self.ndftapplication_number = ndftapplicant.application_number |
|---|
| 90 | self.ndftapplicant = self.app['applicants'][ndftcontainer_name][ |
|---|
| 91 | self.ndftapplication_number] |
|---|
| 92 | self.ndftapplicant_path = ('http://localhost/app/applicants/%s/%s' |
|---|
| 93 | % (ndftcontainer_name, self.ndftapplication_number)) |
|---|
| 94 | |
|---|
| 95 | self.browser = Browser() |
|---|
| 96 | self.browser.handleErrors = False |
|---|
| 97 | |
|---|
| 98 | def tearDown(self): |
|---|
| 99 | super(ApplicantUITest, self).tearDown() |
|---|
| 100 | shutil.rmtree(self.dc_root) |
|---|
| 101 | clearSite() |
|---|
| 102 | return |
|---|
| 103 | |
|---|
| 104 | def fill_correct_values(self): |
|---|
| 105 | self.browser.getControl(name="form.reg_number").value = '1234' |
|---|
| 106 | self.browser.getControl(name="form.firstname").value = 'John' |
|---|
| 107 | self.browser.getControl(name="form.lastname").value = 'Tester' |
|---|
| 108 | self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' |
|---|
| 109 | self.browser.getControl(name="form.lga").value = ['foreigner'] |
|---|
| 110 | #self.browser.getControl(name="form.nationality").value = ['NG'] |
|---|
| 111 | #self.browser.getControl(name="form.sex").value = ['m'] |
|---|
| 112 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
|---|
| 113 | |
|---|
| 114 | def test_manage_and_view_applicant(self): |
|---|
| 115 | # Managers can manage ndft applicants. |
|---|
| 116 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
|---|
| 117 | self.browser.open(self.ndftapplicant_path) |
|---|
| 118 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
|---|
| 119 | self.assertTrue("'O' Level" in self.browser.contents) |
|---|
| 120 | self.assertFalse("Higher" in self.browser.contents) |
|---|
| 121 | self.browser.open(self.ndftapplicant_path + '/manage') |
|---|
| 122 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
|---|
| 123 | self.assertTrue("'O' Level" in self.browser.contents) |
|---|
| 124 | self.assertTrue("Higher" in self.browser.contents) |
|---|
| 125 | self.browser.open(self.ndftapplicant_path + '/edit') |
|---|
| 126 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
|---|
| 127 | self.assertTrue("'O' Level" in self.browser.contents) |
|---|
| 128 | self.assertFalse("Higher" in self.browser.contents) |
|---|
| 129 | self.browser.open(self.ndftapplicant_path + '/application_slip.pdf') |
|---|
| 130 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
|---|
| 131 | # Now we turn the ndft applicant into an hndft applicant. |
|---|
| 132 | self.ndftapplicant.applicant_id = u'hndft_anything' |
|---|
| 133 | self.browser.open(self.ndftapplicant_path) |
|---|
| 134 | self.assertTrue("Higher" in self.browser.contents) |
|---|
| 135 | self.assertTrue("'O' Level" in self.browser.contents) |
|---|
| 136 | self.browser.open(self.ndftapplicant_path + '/edit') |
|---|
| 137 | self.assertTrue("Higher" in self.browser.contents) |
|---|
| 138 | self.assertTrue("'O' Level" in self.browser.contents) |
|---|
| 139 | |
|---|
| 140 | self.browser.open(self.ndftapplicant_path + '/manage') |
|---|
| 141 | # Manager can fill and save the form |
|---|
| 142 | self.fill_correct_values() |
|---|
| 143 | self.browser.getControl("Save").click() |
|---|
| 144 | self.assertMatches('...Form has been saved...', self.browser.contents) |
|---|
| 145 | return |
|---|