1 | ## $Id: test_browser.py 16474 2021-04-23 07:22:53Z 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 os |
---|
19 | import shutil |
---|
20 | import tempfile |
---|
21 | from StringIO import StringIO |
---|
22 | from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo |
---|
23 | from zope.securitypolicy.interfaces import IPrincipalRoleManager |
---|
24 | from zope.component.hooks import setSite, clearSite |
---|
25 | from zope.component import getUtility, createObject |
---|
26 | from zope.interface import verify |
---|
27 | from zope.event import notify |
---|
28 | from waeup.kofa.authentication import LocalRoleSetEvent |
---|
29 | from waeup.kofa.app import University |
---|
30 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
31 | from waeup.kofa.students.accommodation import BedTicket |
---|
32 | from waeup.kofa.browser.tests.test_pdf import samples_dir |
---|
33 | from waeup.kofa.testing import FunctionalTestCase |
---|
34 | from waeup.kofa.interfaces import ( |
---|
35 | IExtFileStore, IFileStoreNameChooser) |
---|
36 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
37 | from kofacustom.coewarri.testing import FunctionalLayer |
---|
38 | |
---|
39 | |
---|
40 | class StudentsContainerUITests(StudentsFullSetup): |
---|
41 | # Tests for StudentsContainer class views and pages |
---|
42 | |
---|
43 | layer = FunctionalLayer |
---|
44 | |
---|
45 | def test_for_instalment_payments(self): |
---|
46 | |
---|
47 | #configuration_1 = createObject('waeup.SessionConfiguration') |
---|
48 | #configuration_1.academic_session = 2015 |
---|
49 | #self.app['configuration'].addSessionConfiguration(configuration_1) |
---|
50 | self.student['studycourse'].certificate.study_mode = 'ug_ft' |
---|
51 | self.student.nationality = u'NG' |
---|
52 | # Fresh student |
---|
53 | IWorkflowState(self.student).setState('cleared') |
---|
54 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
55 | self.browser.open(self.payments_path + '/addop') |
---|
56 | self.browser.open(self.payments_path + '/addop') |
---|
57 | # Add first instalment |
---|
58 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
59 | self.browser.getControl("Create ticket").click() |
---|
60 | self.assertTrue('ticket created' in self.browser.contents) |
---|
61 | self.browser.open(self.payments_path) |
---|
62 | ctrl = self.browser.getControl(name='val_id') |
---|
63 | p_id = ctrl.options[0] |
---|
64 | self.browser.open(self.payments_path + '/' + p_id + '/approve') |
---|
65 | # Add the second instalment ... |
---|
66 | self.browser.open(self.payments_path + '/addop') |
---|
67 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
68 | self.browser.getControl("Create ticket").click() |
---|
69 | self.assertTrue('ticket created' in self.browser.contents) |
---|
70 | # ... approve the second instalment ... |
---|
71 | self.browser.open(self.payments_path) |
---|
72 | ctrl = self.browser.getControl(name='val_id') |
---|
73 | p_id = ctrl.options[1] |
---|
74 | self.browser.open(self.payments_path + '/' + p_id + '/approve') |
---|
75 | self.assertEqual(self.student['payments'].values()[0].p_category, 'schoolfee_1') |
---|
76 | self.assertEqual(self.student['payments'].values()[1].p_category, 'schoolfee_2') |
---|
77 | # 85700/ 2 + 250 |
---|
78 | self.assertEqual(self.student['payments'].values()[0].amount_auth, 43100.0) |
---|
79 | self.assertEqual(self.student['payments'].values()[1].amount_auth, 43100.0) |
---|
80 | # The two payments belong to the same session and level. |
---|
81 | self.assertEqual(self.student['payments'].values()[0].p_session, 2004) |
---|
82 | self.assertEqual(self.student['payments'].values()[0].p_level, 100) |
---|
83 | self.assertEqual(self.student['payments'].values()[1].p_session, 2004) |
---|
84 | self.assertEqual(self.student['payments'].values()[1].p_level, 100) |
---|
85 | |
---|
86 | # Returning student |
---|
87 | configuration_2 = createObject('waeup.SessionConfiguration') |
---|
88 | configuration_2.academic_session = 2005 |
---|
89 | self.app['configuration'].addSessionConfiguration(configuration_2) |
---|
90 | IWorkflowState(self.student).setState('returning') |
---|
91 | self.browser.open(self.payments_path + '/addop') |
---|
92 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
93 | self.browser.getControl("Create ticket").click() |
---|
94 | self.browser.open(self.payments_path + '/addop') |
---|
95 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
96 | self.browser.getControl("Create ticket").click() |
---|
97 | self.browser.open(self.payments_path) |
---|
98 | ctrl = self.browser.getControl(name='val_id') |
---|
99 | # Nothing happens if we approve the 2nd instalment for session 2005 |
---|
100 | self.browser.open(self.payments_path + '/' + ctrl.options[3] + '/approve') |
---|
101 | self.assertEqual(self.student.state, 'returning') |
---|
102 | # Workflow transition is trigered if we approve the 1st indtalment |
---|
103 | self.browser.open(self.payments_path + '/' + ctrl.options[2] + '/approve') |
---|
104 | self.assertEqual(self.student.state, 'school fee paid') |
---|
105 | self.assertEqual(self.student.current_level, 200) |
---|
106 | self.assertEqual(self.student.current_session, 2005) |
---|
107 | # 79700 / 2 + 250 |
---|
108 | self.assertEqual(self.student['payments'].values()[2].amount_auth, 37600.0) |
---|
109 | self.assertEqual(self.student['payments'].values()[3].amount_auth, 37600.0) |
---|
110 | # The last two payments belong to the same session and level. |
---|
111 | self.assertEqual(self.student['payments'].values()[2].p_session, 2005) |
---|
112 | self.assertEqual(self.student['payments'].values()[2].p_level, 200) |
---|
113 | self.assertEqual(self.student['payments'].values()[3].p_session, 2005) |
---|
114 | self.assertEqual(self.student['payments'].values()[3].p_level, 200) |
---|
115 | return |
---|
116 | |
---|
117 | def test_registration_pdf_slips(self): |
---|
118 | # Student cant login if their password is not set |
---|
119 | IWorkflowState(self.student).setState('school fee paid') |
---|
120 | self.browser.open(self.login_path) |
---|
121 | self.browser.getControl(name="form.login").value = self.student_id |
---|
122 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
123 | self.browser.getControl("Login").click() |
---|
124 | self.browser.getLink("Study Course").click() |
---|
125 | self.browser.getLink("Add course list").click() |
---|
126 | self.assertMatches('...Add current level 100 (Year 1)...', |
---|
127 | self.browser.contents) |
---|
128 | self.browser.getControl("Create course list now").click() |
---|
129 | # A level with one course ticket was created |
---|
130 | self.browser.getLink("100").click() |
---|
131 | self.browser.getLink("Download course registration slip").click() |
---|
132 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
133 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
134 | 'application/pdf') |
---|
135 | path = os.path.join(samples_dir(), 'course_registration_slip.pdf') |
---|
136 | open(path, 'wb').write(self.browser.contents) |
---|
137 | print "Sample PDF course_registration_slip.pdf written to %s" % path |
---|