1 | ## $Id: tests.py 9508 2012-11-02 10:50:58Z 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.aaue.testing import FunctionalLayer |
---|
23 | |
---|
24 | |
---|
25 | # Also run tests that send requests to external servers? |
---|
26 | # If you enable this, please make sure the external services |
---|
27 | # do exist really and are not bothered by being spammed by a test programme. |
---|
28 | EXTERNAL_TESTS = False |
---|
29 | |
---|
30 | def external_test(func): |
---|
31 | if not EXTERNAL_TESTS: |
---|
32 | myself = __file__ |
---|
33 | if myself.endswith('.pyc'): |
---|
34 | myself = myself[:-2] |
---|
35 | print "WARNING: external tests are skipped!" |
---|
36 | print "WARNING: edit %s to enable them." % myself |
---|
37 | return |
---|
38 | return func |
---|
39 | |
---|
40 | class EtranzactTestsStudent(StudentsFullSetup): |
---|
41 | """Tests for the eTranzact payment gateway. |
---|
42 | """ |
---|
43 | |
---|
44 | layer = FunctionalLayer |
---|
45 | |
---|
46 | CONFIRMATION_NO = '500856521315472785095' |
---|
47 | |
---|
48 | def setUp(self): |
---|
49 | super(EtranzactTestsStudent, self).setUp() |
---|
50 | # Managers can add online payment tickets |
---|
51 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
52 | self.app['configuration']['2004'].school_fee_base = 1234.0 |
---|
53 | self.browser.open(self.payments_path) |
---|
54 | IWorkflowState(self.student).setState('cleared') |
---|
55 | self.browser.open(self.payments_path + '/addop') |
---|
56 | self.browser.getControl("Create ticket").click() |
---|
57 | self.assertMatches('...ticket created...', |
---|
58 | self.browser.contents) |
---|
59 | |
---|
60 | ctrl = self.browser.getControl(name='val_id') |
---|
61 | value = ctrl.options[0] |
---|
62 | self.p_id = value |
---|
63 | self.browser.getLink(value).click() |
---|
64 | self.assertMatches('...Amount Authorized...', |
---|
65 | self.browser.contents) |
---|
66 | self.payment_url = self.browser.url |
---|
67 | |
---|
68 | def test_enterpin(self): |
---|
69 | self.browser.getLink("Query eTranzact History").click() |
---|
70 | self.assertMatches( |
---|
71 | '...Confirmation Number (PIN):...', |
---|
72 | self.browser.contents) |
---|
73 | |
---|
74 | def test_webservice(self): |
---|
75 | self.browser.open('http://localhost/app/feerequest?PAYEE_ID=%s' % self.p_id) |
---|
76 | self.assertEqual(self.browser.contents, |
---|
77 | 'FULL_NAME=Anna Tester&' |
---|
78 | 'FACULTY=fac1&' |
---|
79 | 'DEPARTMENT=dep1&' |
---|
80 | 'RETURN_TYPE=%s&' |
---|
81 | 'PROGRAMME_TYPE=CERT1&' |
---|
82 | 'PAYMENT_TYPE=School Fee 1st instalment&' |
---|
83 | 'ACADEMIC_SESSION=2004/2005&' |
---|
84 | 'MATRIC_NO=E1000000&' |
---|
85 | 'FEE_AMOUNT=1234.0&' |
---|
86 | 'TRANSACTION_STATUS=unpaid' % self.p_id) |
---|
87 | self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense') |
---|
88 | self.assertEqual(self.browser.contents, '-1') |
---|
89 | |
---|
90 | @external_test |
---|
91 | def test_etranzact_query_history(self): |
---|
92 | |
---|
93 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
94 | % self.CONFIRMATION_NO) |
---|
95 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
96 | self.browser.contents) |
---|
97 | #self.assertMatches('...Wrong amount...', |
---|
98 | # self.browser.contents) |
---|
99 | #self.student['payments'][value].amount_auth = self.student[ |
---|
100 | # 'payments'][value].r_amount_approved |
---|
101 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
102 | # % self.CONFIRMATION_NO) |
---|
103 | #self.assertMatches('...Wrong transaction id...', |
---|
104 | # self.browser.contents) |
---|
105 | |
---|
106 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
---|
107 | """Tests for the Interswitch payment gateway. |
---|
108 | """ |
---|
109 | |
---|
110 | layer = FunctionalLayer |
---|
111 | |
---|
112 | CONFIRMATION_NO = '500856521315472785095' |
---|
113 | |
---|
114 | def setUp(self): |
---|
115 | super(EtranzactTestsApplicants, self).setUp() |
---|
116 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
117 | self.browser.open(self.manage_path) |
---|
118 | #IWorkflowState(self.student).setState('started') |
---|
119 | super(EtranzactTestsApplicants, self).fill_correct_values() |
---|
120 | self.browser.getControl(name="transition").value = ['start'] |
---|
121 | self.browser.getControl("Save").click() |
---|
122 | self.browser.getControl("Add online").click() |
---|
123 | self.assertTrue( |
---|
124 | 'Session configuration object is not available' |
---|
125 | in self.browser.contents) |
---|
126 | configuration = SessionConfiguration() |
---|
127 | configuration.academic_session = 2009 |
---|
128 | configuration.application_fee = 1000.0 |
---|
129 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
130 | self.browser.open(self.manage_path) |
---|
131 | self.browser.getControl("Add online").click() |
---|
132 | self.assertMatches('...ticket created...', |
---|
133 | self.browser.contents) |
---|
134 | self.assertMatches('...Amount Authorized...', |
---|
135 | self.browser.contents) |
---|
136 | self.assertMatches( |
---|
137 | '...<span>1000.0</span>...', |
---|
138 | self.browser.contents) |
---|
139 | self.payment_url = self.browser.url |
---|
140 | |
---|
141 | @external_test |
---|
142 | def test_etranzact_query_history(self): |
---|
143 | |
---|
144 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
145 | % self.CONFIRMATION_NO) |
---|
146 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
147 | self.browser.contents) |
---|
148 | #self.assertMatches('...Wrong amount...', |
---|
149 | # self.browser.contents) |
---|
150 | #self.applicant[value].amount_auth = self.applicant[ |
---|
151 | # value].r_amount_approved |
---|
152 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
153 | # % self.CONFIRMATION_NO) |
---|
154 | #self.assertMatches('...Wrong transaction id...', |
---|
155 | # self.browser.contents) |
---|