source: main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/applicants/tests/test_browser.py @ 15123

Last change on this file since 15123 was 15123, checked in by Henrik Bettermann, 6 years ago

Applicants have to pay an admission checking fee before they can view their admission 'status'.

  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1## $Id: test_browser.py 15123 2018-09-05 10:58:59Z henrik $
2##
3## Copyright (C) 2013 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"""
19Test the applicant-related UI components.
20"""
21import os
22import datetime
23from zope.component import createObject, getUtility
24from zope.catalog.interfaces import ICatalog
25from zope.intid.interfaces import IIntIds
26from hurry.workflow.interfaces import IWorkflowState
27from kofacustom.edopoly.testing import FunctionalLayer
28from waeup.kofa.browser.tests.test_pdf import samples_dir
29from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
30from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
31from kofacustom.edopoly.applicants.export import CustomApplicantExporter
32from kofacustom.edopoly.applicants.batching import CustomApplicantProcessor
33from kofacustom.edopoly.configuration import CustomSessionConfiguration
34
35class CustomApplicantUITests(ApplicantsFullSetup):
36    # Tests for uploading/browsing the passport image of appplicants
37
38    layer = FunctionalLayer
39
40    def test_pay_admission_checking_fee(self):
41        IWorkflowState(self.applicant).setState('admitted')
42        self.applicant.screening_score = 55
43        self.applicant.course_admitted = self.certificate
44        self.login()
45        # SessionConfiguration is not set, thus admission checking payment
46        # is not necessary. Screening results and course admitted are visible.
47        self.assertFalse(
48            'Add admission checking payment ticket' in self.browser.contents)
49        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
50        self.assertTrue('<span>55</span>' in self.browser.contents)
51        configuration = CustomSessionConfiguration()
52        configuration.academic_session = datetime.datetime.now().year - 2
53        self.app['configuration'].addSessionConfiguration(configuration)
54        # Admission checking fee is 0, thus admission checking payment
55        # is not necessary. Screening results and course admitted are visible.
56        self.browser.open(self.view_path)
57        self.assertFalse(
58            'Add admission checking payment ticket' in self.browser.contents)
59        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
60        self.assertTrue('<span>55</span>' in self.browser.contents)
61        configuration.admchecking_fee = 22.0
62        # Admission checking payment button is now visible, but screening results
63        # and course admitted are not.
64        self.browser.open(self.view_path)
65        self.assertTrue(
66            'Add admission checking payment ticket' in self.browser.contents)
67        self.assertFalse('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
68        self.assertFalse('<span>55</span>' in self.browser.contents)
69        # Application slip can't be downloaded
70        self.assertFalse('Download application slip' in self.browser.contents)
71        slip_path = self.view_path + '/application_slip.pdf'
72        self.browser.open(slip_path)
73        self.assertTrue(
74            'Please pay admission checking fee before trying to download'
75            in self.browser.contents)
76        # Pay admission checking fee.
77        self.browser.getControl("Add admission checking").click()
78        p_id = self.applicant.keys()[0]
79        self.applicant[p_id].p_state = 'paid'
80        # Screening results and course admitted are visible after payment.
81        self.browser.open(self.view_path)
82        self.assertFalse(
83            'Add admission checking payment ticket' in self.browser.contents)
84        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
85        self.assertTrue('<span>55</span>' in self.browser.contents)
86        # Application slip can be downloaded again.
87        self.browser.getLink("Download application slip").click()
88        self.assertEqual(self.browser.headers['Status'], '200 Ok')
89        self.assertEqual(self.browser.headers['Content-Type'],
90                         'application/pdf')
91        return
92
93class ApplicantExporterTest(ApplicantImportExportSetup):
94
95    layer = FunctionalLayer
96
97    def setUp(self):
98        super(ApplicantExporterTest, self).setUp()
99        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
100        self.cat = getUtility(ICatalog, name='applicants_catalog')
101        self.intids = getUtility(IIntIds)
102        return
103
104    def setup_applicant(self, applicant):
105        # set predictable values for `applicant`
106        applicant.reg_number = u'123456'
107        applicant.applicant_id = u'dp2011_654321'
108        applicant.firstname = u'Anna'
109        applicant.lastname = u'Tester'
110        applicant.middlename = u'M.'
111        applicant.nationality = u'NG'
112        applicant.date_of_birth = datetime.date(1981, 2, 4)
113        applicant.sex = 'f'
114        applicant.email = 'anna@sample.com'
115        applicant.phone = u'+234-123-12345'
116        applicant.course1 = self.certificate
117        applicant.course2 = self.certificate
118        applicant.course_admitted = self.certificate
119        applicant.notice = u'Some notice\nin lines.'
120        applicant.screening_score = 98
121        applicant.screening_venue = u'Exam Room'
122        applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM'
123        applicant.password = 'any password'
124        return applicant
125
126class ApplicantsContainerUITests(ApplicantsFullSetup):
127    # Tests for ApplicantsContainer class views and pages
128
129    layer = FunctionalLayer
130
131    def test_application_slip(self):
132        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
133        self.slip_path = self.view_path + '/application_slip.pdf'
134        self.browser.open(self.manage_path)
135        self.assertEqual(self.browser.headers['Status'], '200 Ok')
136        self.fill_correct_values()
137        self.browser.getControl("Save").click()
138        IWorkflowState(self.applicant).setState('submitted')
139        self.browser.open(self.manage_path)
140        self.browser.getLink("Download application slip").click()
141        self.assertEqual(self.browser.headers['Status'], '200 Ok')
142        self.assertEqual(self.browser.headers['Content-Type'],
143                         'application/pdf')
144        path = os.path.join(samples_dir(), 'application_slip.pdf')
145        open(path, 'wb').write(self.browser.contents)
146        print "Sample application_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.