[7929] | 1 | ## $Id: tests.py 11554 2014-03-30 05:52:51Z 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 |
---|
[8267] | 20 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
| 21 | from waeup.kofa.configuration import SessionConfiguration |
---|
[8444] | 22 | from waeup.aaue.testing import FunctionalLayer |
---|
[10978] | 23 | from waeup.aaue.etranzact.browser import ERROR_PART1, ERROR_PART2 |
---|
[7929] | 24 | |
---|
[7970] | 25 | |
---|
| 26 | # Also run tests that send requests to external servers? |
---|
| 27 | # If you enable this, please make sure the external services |
---|
| 28 | # do exist really and are not bothered by being spammed by a test programme. |
---|
[8271] | 29 | EXTERNAL_TESTS = False |
---|
[7970] | 30 | |
---|
| 31 | def external_test(func): |
---|
| 32 | if not EXTERNAL_TESTS: |
---|
| 33 | myself = __file__ |
---|
| 34 | if myself.endswith('.pyc'): |
---|
| 35 | myself = myself[:-2] |
---|
| 36 | print "WARNING: external tests are skipped!" |
---|
| 37 | print "WARNING: edit %s to enable them." % myself |
---|
| 38 | return |
---|
| 39 | return func |
---|
| 40 | |
---|
[8267] | 41 | class EtranzactTestsStudent(StudentsFullSetup): |
---|
[7976] | 42 | """Tests for the eTranzact payment gateway. |
---|
[7929] | 43 | """ |
---|
| 44 | |
---|
| 45 | layer = FunctionalLayer |
---|
| 46 | |
---|
| 47 | CONFIRMATION_NO = '500856521315472785095' |
---|
| 48 | |
---|
[7976] | 49 | def setUp(self): |
---|
[8267] | 50 | super(EtranzactTestsStudent, self).setUp() |
---|
[7929] | 51 | # Managers can add online payment tickets |
---|
| 52 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[9905] | 53 | self.app['configuration']['2004'].school_fee = 1234.0 |
---|
[7995] | 54 | self.browser.open(self.payments_path) |
---|
[7929] | 55 | IWorkflowState(self.student).setState('cleared') |
---|
[7995] | 56 | self.browser.open(self.payments_path + '/addop') |
---|
[9905] | 57 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
[7929] | 58 | self.browser.getControl("Create ticket").click() |
---|
| 59 | self.assertMatches('...ticket created...', |
---|
| 60 | self.browser.contents) |
---|
[8754] | 61 | |
---|
[7929] | 62 | ctrl = self.browser.getControl(name='val_id') |
---|
| 63 | value = ctrl.options[0] |
---|
[8731] | 64 | self.p_id = value |
---|
[7929] | 65 | self.browser.getLink(value).click() |
---|
| 66 | self.assertMatches('...Amount Authorized...', |
---|
| 67 | self.browser.contents) |
---|
[7976] | 68 | self.payment_url = self.browser.url |
---|
| 69 | |
---|
| 70 | def test_enterpin(self): |
---|
| 71 | self.browser.getLink("Query eTranzact History").click() |
---|
| 72 | self.assertMatches( |
---|
[11291] | 73 | '...Confirmation Number (PIN)...', |
---|
[7976] | 74 | self.browser.contents) |
---|
| 75 | |
---|
[8731] | 76 | def test_webservice(self): |
---|
[10937] | 77 | self.browser.open( |
---|
| 78 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE' |
---|
| 79 | % self.p_id) |
---|
[8731] | 80 | self.assertEqual(self.browser.contents, |
---|
[10907] | 81 | # Version 1 |
---|
| 82 | #'FULL_NAME=Anna Tester&' |
---|
| 83 | #'FACULTY=fac1&' |
---|
| 84 | #'DEPARTMENT=dep1&' |
---|
| 85 | #'RETURN_TYPE=%s&' |
---|
| 86 | #'PROGRAMME_TYPE=CERT1&' |
---|
| 87 | #'PAYMENT_TYPE=School Fee&' |
---|
| 88 | #'ACADEMIC_SESSION=2004/2005&' |
---|
| 89 | #'MATRIC_NO=E1000000&' |
---|
| 90 | #'FEE_AMOUNT=1234.0&' |
---|
| 91 | #'TRANSACTION_STATUS=unpaid' |
---|
| 92 | |
---|
| 93 | # Version 2 |
---|
| 94 | 'PayeeName=Anna Tester~' |
---|
| 95 | 'Faculty=fac1~' |
---|
| 96 | 'Department=dep1~' |
---|
| 97 | 'Level=100~' |
---|
| 98 | 'ProgrammeType=CERT1~' |
---|
| 99 | 'StudyType=ug_ft~' |
---|
| 100 | 'Session=2004/2005~' |
---|
| 101 | 'PayeeID=%s~' |
---|
| 102 | 'Amount=1234.0~' |
---|
| 103 | 'FeeStatus=unpaid~' |
---|
[10932] | 104 | 'Semester=N/A~' |
---|
[10907] | 105 | 'PaymentType=School Fee~' |
---|
| 106 | 'MatricNumber=E1000000~' |
---|
| 107 | 'Email=aa@aa.ng~' |
---|
| 108 | 'PhoneNumber=1234' % self.p_id) |
---|
| 109 | |
---|
[10937] | 110 | self.browser.open('http://localhost/app/feerequest') |
---|
[10978] | 111 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
---|
[9508] | 112 | self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense') |
---|
[10978] | 113 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2) |
---|
[10937] | 114 | self.browser.open( |
---|
[10954] | 115 | 'http://localhost/app/feerequest?PAYEE_ID=nonsense&PAYMENT_TYPE=SCHOOL-FEE') |
---|
[10978] | 116 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2) |
---|
[10954] | 117 | self.browser.open( |
---|
[10937] | 118 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE' |
---|
| 119 | % self.p_id) |
---|
[10978] | 120 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
---|
[10937] | 121 | self.browser.open( |
---|
| 122 | 'http://localhost/app/feerequest?PAYEE_ID=%s' |
---|
| 123 | % self.p_id) |
---|
[10978] | 124 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2) |
---|
[10937] | 125 | self.browser.open( |
---|
| 126 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE' |
---|
| 127 | % self.p_id) |
---|
[10978] | 128 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
[10937] | 129 | self.browser.open( |
---|
| 130 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE' |
---|
| 131 | % self.p_id) |
---|
[10978] | 132 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2) |
---|
[11554] | 133 | self.student['payments'][self.p_id].p_state = 'paid' |
---|
| 134 | self.browser.open( |
---|
| 135 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE' |
---|
| 136 | % self.p_id) |
---|
| 137 | self.assertEqual(self.browser.contents, ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2) |
---|
[8731] | 138 | |
---|
[10937] | 139 | |
---|
[7976] | 140 | @external_test |
---|
| 141 | def test_etranzact_query_history(self): |
---|
| 142 | |
---|
| 143 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 144 | % self.CONFIRMATION_NO) |
---|
[8267] | 145 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 146 | self.browser.contents) |
---|
[8267] | 147 | #self.assertMatches('...Wrong amount...', |
---|
| 148 | # self.browser.contents) |
---|
| 149 | #self.student['payments'][value].amount_auth = self.student[ |
---|
| 150 | # 'payments'][value].r_amount_approved |
---|
| 151 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 152 | # % self.CONFIRMATION_NO) |
---|
| 153 | #self.assertMatches('...Wrong transaction id...', |
---|
| 154 | # self.browser.contents) |
---|
[7929] | 155 | |
---|
[8267] | 156 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
---|
| 157 | """Tests for the Interswitch payment gateway. |
---|
| 158 | """ |
---|
| 159 | |
---|
| 160 | layer = FunctionalLayer |
---|
| 161 | |
---|
| 162 | CONFIRMATION_NO = '500856521315472785095' |
---|
| 163 | |
---|
| 164 | def setUp(self): |
---|
| 165 | super(EtranzactTestsApplicants, self).setUp() |
---|
| 166 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 167 | self.browser.open(self.manage_path) |
---|
| 168 | #IWorkflowState(self.student).setState('started') |
---|
| 169 | super(EtranzactTestsApplicants, self).fill_correct_values() |
---|
| 170 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 171 | self.browser.getControl("Save").click() |
---|
| 172 | self.browser.getControl("Add online").click() |
---|
| 173 | self.assertTrue( |
---|
| 174 | 'Session configuration object is not available' |
---|
| 175 | in self.browser.contents) |
---|
| 176 | configuration = SessionConfiguration() |
---|
| 177 | configuration.academic_session = 2009 |
---|
| 178 | configuration.application_fee = 1000.0 |
---|
| 179 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
[8430] | 180 | self.browser.open(self.manage_path) |
---|
[8267] | 181 | self.browser.getControl("Add online").click() |
---|
| 182 | self.assertMatches('...ticket created...', |
---|
| 183 | self.browser.contents) |
---|
| 184 | self.assertMatches('...Amount Authorized...', |
---|
| 185 | self.browser.contents) |
---|
| 186 | self.assertMatches( |
---|
| 187 | '...<span>1000.0</span>...', |
---|
| 188 | self.browser.contents) |
---|
| 189 | self.payment_url = self.browser.url |
---|
| 190 | |
---|
| 191 | @external_test |
---|
| 192 | def test_etranzact_query_history(self): |
---|
| 193 | |
---|
[7976] | 194 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 195 | % self.CONFIRMATION_NO) |
---|
[8267] | 196 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 197 | self.browser.contents) |
---|
[8267] | 198 | #self.assertMatches('...Wrong amount...', |
---|
| 199 | # self.browser.contents) |
---|
| 200 | #self.applicant[value].amount_auth = self.applicant[ |
---|
| 201 | # value].r_amount_approved |
---|
| 202 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 203 | # % self.CONFIRMATION_NO) |
---|
| 204 | #self.assertMatches('...Wrong transaction id...', |
---|
| 205 | # self.browser.contents) |
---|