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

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

Hide workflow state and history if admission checking fee has not been paid.

  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1## $Id: test_browser.py 15131 2018-09-07 09:01:25Z 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        # History and state is also missing
77        self.assertFalse('...' in self.browser.contents)
78        self.assertFalse('Application initialized' in self.browser.contents)
79        # Pay admission checking fee.
80        self.browser.getControl("Add admission checking").click()
81        p_id = self.applicant.keys()[0]
82        self.applicant[p_id].p_state = 'paid'
83        # Screening results and course admitted are visible after payment.
84        self.browser.open(self.view_path)
85        self.assertFalse(
86            'Add admission checking payment ticket' in self.browser.contents)
87        self.assertTrue('<a href="http://localhost/app/faculties/fac1/dep1/certificates/CERT1">CERT1 - Unnamed Certificate</a>' in self.browser.contents)
88        self.assertTrue('<span>55</span>' in self.browser.contents)
89        # History and state are visible
90        self.assertTrue('...' in self.browser.contents)
91        self.assertTrue('Application initialized' in self.browser.contents)
92        # Application slip can be downloaded again.
93        self.browser.getLink("Download application slip").click()
94        self.assertEqual(self.browser.headers['Status'], '200 Ok')
95        self.assertEqual(self.browser.headers['Content-Type'],
96                         'application/pdf')
97        return
98
99class ApplicantExporterTest(ApplicantImportExportSetup):
100
101    layer = FunctionalLayer
102
103    def setUp(self):
104        super(ApplicantExporterTest, self).setUp()
105        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
106        self.cat = getUtility(ICatalog, name='applicants_catalog')
107        self.intids = getUtility(IIntIds)
108        return
109
110    def setup_applicant(self, applicant):
111        # set predictable values for `applicant`
112        applicant.reg_number = u'123456'
113        applicant.applicant_id = u'dp2011_654321'
114        applicant.firstname = u'Anna'
115        applicant.lastname = u'Tester'
116        applicant.middlename = u'M.'
117        applicant.nationality = u'NG'
118        applicant.date_of_birth = datetime.date(1981, 2, 4)
119        applicant.sex = 'f'
120        applicant.email = 'anna@sample.com'
121        applicant.phone = u'+234-123-12345'
122        applicant.course1 = self.certificate
123        applicant.course2 = self.certificate
124        applicant.course_admitted = self.certificate
125        applicant.notice = u'Some notice\nin lines.'
126        applicant.screening_score = 98
127        applicant.screening_venue = u'Exam Room'
128        applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM'
129        applicant.password = 'any password'
130        return applicant
131
132class ApplicantsContainerUITests(ApplicantsFullSetup):
133    # Tests for ApplicantsContainer class views and pages
134
135    layer = FunctionalLayer
136
137    def test_application_slip(self):
138        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
139        self.slip_path = self.view_path + '/application_slip.pdf'
140        self.browser.open(self.manage_path)
141        self.assertEqual(self.browser.headers['Status'], '200 Ok')
142        self.fill_correct_values()
143        self.browser.getControl("Save").click()
144        IWorkflowState(self.applicant).setState('submitted')
145        self.browser.open(self.manage_path)
146        self.browser.getLink("Download application slip").click()
147        self.assertEqual(self.browser.headers['Status'], '200 Ok')
148        self.assertEqual(self.browser.headers['Content-Type'],
149                         'application/pdf')
150        path = os.path.join(samples_dir(), 'application_slip.pdf')
151        open(path, 'wb').write(self.browser.contents)
152        print "Sample application_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.