1 | ## $Id: test_browser.py 14344 2016-12-14 16:57:13Z 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.testing import FunctionalTestCase |
---|
33 | from waeup.kofa.interfaces import ( |
---|
34 | IExtFileStore, IFileStoreNameChooser) |
---|
35 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
36 | from kofacustom.coewarri.testing import FunctionalLayer |
---|
37 | |
---|
38 | |
---|
39 | class StudentsContainerUITests(StudentsFullSetup): |
---|
40 | # Tests for StudentsContainer class views and pages |
---|
41 | |
---|
42 | layer = FunctionalLayer |
---|
43 | |
---|
44 | def test_for_instalment_payments(self): |
---|
45 | |
---|
46 | #configuration_1 = createObject('waeup.SessionConfiguration') |
---|
47 | #configuration_1.academic_session = 2015 |
---|
48 | #self.app['configuration'].addSessionConfiguration(configuration_1) |
---|
49 | self.student['studycourse'].certificate.study_mode = 'ug_ft' |
---|
50 | self.student.nationality = u'NG' |
---|
51 | # Fresh student |
---|
52 | IWorkflowState(self.student).setState('cleared') |
---|
53 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
54 | self.browser.open(self.payments_path + '/addop') |
---|
55 | self.browser.open(self.payments_path + '/addop') |
---|
56 | # Add first instalment |
---|
57 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
58 | self.browser.getControl("Create ticket").click() |
---|
59 | self.assertTrue('ticket created' in self.browser.contents) |
---|
60 | self.browser.open(self.payments_path) |
---|
61 | ctrl = self.browser.getControl(name='val_id') |
---|
62 | p_id = ctrl.options[0] |
---|
63 | self.browser.open(self.payments_path + '/' + p_id + '/approve') |
---|
64 | # Add the second instalment ... |
---|
65 | self.browser.open(self.payments_path + '/addop') |
---|
66 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
67 | self.browser.getControl("Create ticket").click() |
---|
68 | self.assertTrue('ticket created' in self.browser.contents) |
---|
69 | # ... approve the second instalment ... |
---|
70 | ctrl = self.browser.getControl(name='val_id') |
---|
71 | p_id = ctrl.options[1] |
---|
72 | self.browser.open(self.payments_path + '/' + p_id + '/approve') |
---|
73 | self.assertEqual(self.student['payments'].values()[0].p_category, 'schoolfee_1') |
---|
74 | self.assertEqual(self.student['payments'].values()[1].p_category, 'schoolfee_2') |
---|
75 | # 79200 / 2 + 300 |
---|
76 | self.assertEqual(self.student['payments'].values()[0].amount_auth, 39900.0) |
---|
77 | self.assertEqual(self.student['payments'].values()[1].amount_auth, 39900.0) |
---|
78 | # The two payments belong to the same session and level. |
---|
79 | self.assertEqual(self.student['payments'].values()[0].p_session, 2004) |
---|
80 | self.assertEqual(self.student['payments'].values()[0].p_level, 100) |
---|
81 | self.assertEqual(self.student['payments'].values()[1].p_session, 2004) |
---|
82 | self.assertEqual(self.student['payments'].values()[1].p_level, 100) |
---|
83 | |
---|
84 | # Returning student |
---|
85 | configuration_2 = createObject('waeup.SessionConfiguration') |
---|
86 | configuration_2.academic_session = 2005 |
---|
87 | self.app['configuration'].addSessionConfiguration(configuration_2) |
---|
88 | IWorkflowState(self.student).setState('returning') |
---|
89 | self.browser.open(self.payments_path + '/addop') |
---|
90 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
91 | self.browser.getControl("Create ticket").click() |
---|
92 | self.browser.open(self.payments_path + '/addop') |
---|
93 | self.browser.getControl(name="form.p_category").value = ['schoolfee_2'] |
---|
94 | self.browser.getControl("Create ticket").click() |
---|
95 | self.browser.open(self.payments_path) |
---|
96 | ctrl = self.browser.getControl(name='val_id') |
---|
97 | # Nothing happens if we approve the 2nd instalment for session 2005 |
---|
98 | self.browser.open(self.payments_path + '/' + ctrl.options[3] + '/approve') |
---|
99 | self.assertEqual(self.student.state, 'returning') |
---|
100 | # Workflow transition is trigered if we approve the 1st indtalment |
---|
101 | self.browser.open(self.payments_path + '/' + ctrl.options[2] + '/approve') |
---|
102 | self.assertEqual(self.student.state, 'school fee paid') |
---|
103 | self.assertEqual(self.student.current_level, 200) |
---|
104 | self.assertEqual(self.student.current_session, 2005) |
---|
105 | # 63100 / 2 + 300 |
---|
106 | self.assertEqual(self.student['payments'].values()[2].amount_auth, 31850.0) |
---|
107 | self.assertEqual(self.student['payments'].values()[3].amount_auth, 31850.0) |
---|
108 | # The last two payments belong to the same session and level. |
---|
109 | self.assertEqual(self.student['payments'].values()[2].p_session, 2005) |
---|
110 | self.assertEqual(self.student['payments'].values()[2].p_level, 200) |
---|
111 | self.assertEqual(self.student['payments'].values()[3].p_session, 2005) |
---|
112 | self.assertEqual(self.student['payments'].values()[3].p_level, 200) |
---|
113 | return |
---|