1 | ## $Id: tests.py 9432 2012-10-26 21:46:06Z 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 | from hurry.workflow.interfaces import IWorkflowState |
---|
19 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
20 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
21 | from waeup.kofa.configuration import SessionConfiguration |
---|
22 | from waeup.futminna.testing import FunctionalLayer |
---|
23 | |
---|
24 | # Also run tests that send requests to external servers? |
---|
25 | # If you enable this, please make sure the external services |
---|
26 | # do exist really and are not bothered by being spammed by a test programme. |
---|
27 | EXTERNAL_TESTS = False |
---|
28 | |
---|
29 | def external_test(func): |
---|
30 | if not EXTERNAL_TESTS: |
---|
31 | myself = __file__ |
---|
32 | if myself.endswith('.pyc'): |
---|
33 | myself = myself[:-2] |
---|
34 | print "WARNING: external tests are skipped!" |
---|
35 | print "WARNING: edit %s to enable them." % myself |
---|
36 | return |
---|
37 | return func |
---|
38 | |
---|
39 | |
---|
40 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
41 | """Tests for the Interswitch payment gateway. |
---|
42 | """ |
---|
43 | |
---|
44 | layer = FunctionalLayer |
---|
45 | |
---|
46 | def setUp(self): |
---|
47 | super(InterswitchTestsStudents, self).setUp() |
---|
48 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
49 | self.browser.open(self.payments_path) |
---|
50 | IWorkflowState(self.student).setState('cleared') |
---|
51 | self.browser.open(self.payments_path + '/addop') |
---|
52 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
53 | self.browser.getControl("Create ticket").click() |
---|
54 | self.assertMatches('...Payment ticket created...', |
---|
55 | self.browser.contents) |
---|
56 | ctrl = self.browser.getControl(name='val_id') |
---|
57 | value = ctrl.options[0] |
---|
58 | self.browser.getLink(value).click() |
---|
59 | self.assertMatches('...Amount Authorized...', |
---|
60 | self.browser.contents) |
---|
61 | self.assertMatches( |
---|
62 | '...<span>131500.0</span>...', |
---|
63 | self.browser.contents) |
---|
64 | self.payment_url = self.browser.url |
---|
65 | |
---|
66 | def test_interswitch_form(self): |
---|
67 | # Manager can access InterswitchForm |
---|
68 | self.browser.getLink("CollegePAY", index=0).click() |
---|
69 | # The total amount to be processed by Interswitch |
---|
70 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
71 | self.assertMatches('...Total Amount Authorized:...', |
---|
72 | self.browser.contents) |
---|
73 | self.assertMatches( |
---|
74 | '...<input type="hidden" name="amount" value="13150000.0" />...', |
---|
75 | self.browser.contents) |
---|
76 | self.assertMatches( |
---|
77 | '...item_name="School Fee" item_amt="12970000" bank_id="89" acct_num="0030001000017110"...', |
---|
78 | self.browser.contents) |
---|
79 | self.assertMatches( |
---|
80 | '...item_name="BT Education" item_amt="150000" bank_id="89" acct_num="0061001000021095"...', |
---|
81 | self.browser.contents) |
---|
82 | |
---|
83 | # Create clearance fee ticket |
---|
84 | self.browser.open(self.payments_path + '/addop') |
---|
85 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
86 | self.browser.getControl("Create ticket").click() |
---|
87 | self.assertMatches('...ticket created...', |
---|
88 | self.browser.contents) |
---|
89 | ctrl = self.browser.getControl(name='val_id') |
---|
90 | value = ctrl.options[1] |
---|
91 | self.browser.getLink(value).click() |
---|
92 | self.assertMatches('...Amount Authorized...', |
---|
93 | self.browser.contents) |
---|
94 | self.assertMatches( |
---|
95 | '...<span>20000.0</span>...', |
---|
96 | self.browser.contents) |
---|
97 | # Manager can access InterswitchForm |
---|
98 | self.browser.getLink("CollegePAY", index=0).click() |
---|
99 | # The total amount to be processed by Interswitch |
---|
100 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
101 | self.assertMatches('...Total Amount Authorized:...', |
---|
102 | self.browser.contents) |
---|
103 | self.assertMatches( |
---|
104 | '...<input type="hidden" name="amount" value="2000000.0" />...', |
---|
105 | self.browser.contents) |
---|
106 | self.assertMatches( |
---|
107 | '...item_name="Acceptance Fee" item_amt="1970000" bank_id="120" acct_num="1750005063"...', |
---|
108 | self.browser.contents) |
---|
109 | # BT does nor charge a fee for clearance |
---|
110 | self.assertFalse("BT Education" in self.browser.contents) |
---|
111 | |
---|
112 | # Create hostel maintenance ticket |
---|
113 | self.browser.open(self.payments_path + '/addop') |
---|
114 | self.browser.getControl(name="form.p_category").value = ['hostel_maintenance'] |
---|
115 | self.browser.getControl("Create ticket").click() |
---|
116 | self.assertMatches('...You have not yet booked accommodation...', |
---|
117 | self.browser.contents) |
---|
118 | # Students have to book bed first |
---|
119 | self.browser.open(self.acco_path) |
---|
120 | IWorkflowState(self.student).setState('admitted') |
---|
121 | self.browser.getLink("Book accommodation").click() |
---|
122 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
123 | self.browser.getControl("Create bed ticket").click() |
---|
124 | # Bed is randomly selected but, since there is only |
---|
125 | # one bed for this student, we know that ... |
---|
126 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
127 | self.browser.contents) |
---|
128 | self.browser.open(self.payments_path + '/addop') |
---|
129 | self.browser.getControl(name="form.p_category").value = ['hostel_maintenance'] |
---|
130 | self.browser.getControl("Create ticket").click() |
---|
131 | self.assertMatches('...ticket created...', |
---|
132 | self.browser.contents) |
---|
133 | ctrl = self.browser.getControl(name='val_id') |
---|
134 | value = ctrl.options[2] |
---|
135 | self.browser.getLink(value).click() |
---|
136 | self.assertMatches('...Amount Authorized...', |
---|
137 | self.browser.contents) |
---|
138 | self.assertMatches( |
---|
139 | '...<span>10000.0</span>...', |
---|
140 | self.browser.contents) |
---|
141 | # Manager can access InterswitchForm |
---|
142 | self.browser.getLink("CollegePAY", index=0).click() |
---|
143 | # The total amount to be processed by Interswitch |
---|
144 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
145 | self.assertMatches('...Total Amount Authorized:...', |
---|
146 | self.browser.contents) |
---|
147 | self.assertMatches( |
---|
148 | '...<input type="hidden" name="amount" value="1000000.0" />...', |
---|
149 | self.browser.contents) |
---|
150 | self.assertMatches( |
---|
151 | '...item_name="Hostel Maintenance Fee" item_amt="970000" bank_id="8" acct_num="2018856637"...', |
---|
152 | self.browser.contents) |
---|
153 | # BT does nor charge a fee for clearance |
---|
154 | self.assertFalse("BT Education" in self.browser.contents) |
---|
155 | |
---|
156 | |
---|
157 | @external_test |
---|
158 | def test_webservice(self): |
---|
159 | self.browser.open(self.payment_url + '/request_webservice') |
---|
160 | self.assertMatches('...Unsuccessful callback...', |
---|
161 | self.browser.contents) |
---|
162 | # The payment is now in state failed |
---|
163 | self.assertMatches('...<span>Failed</span>...', |
---|
164 | self.browser.contents) |
---|