[7929] | 1 | ## $Id: tests.py 11291 2014-02-22 20:41:35Z uli $ |
---|
| 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) |
---|
[8731] | 133 | |
---|
[10937] | 134 | |
---|
[7976] | 135 | @external_test |
---|
| 136 | def test_etranzact_query_history(self): |
---|
| 137 | |
---|
| 138 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 139 | % self.CONFIRMATION_NO) |
---|
[8267] | 140 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 141 | self.browser.contents) |
---|
[8267] | 142 | #self.assertMatches('...Wrong amount...', |
---|
| 143 | # self.browser.contents) |
---|
| 144 | #self.student['payments'][value].amount_auth = self.student[ |
---|
| 145 | # 'payments'][value].r_amount_approved |
---|
| 146 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 147 | # % self.CONFIRMATION_NO) |
---|
| 148 | #self.assertMatches('...Wrong transaction id...', |
---|
| 149 | # self.browser.contents) |
---|
[7929] | 150 | |
---|
[8267] | 151 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
---|
| 152 | """Tests for the Interswitch payment gateway. |
---|
| 153 | """ |
---|
| 154 | |
---|
| 155 | layer = FunctionalLayer |
---|
| 156 | |
---|
| 157 | CONFIRMATION_NO = '500856521315472785095' |
---|
| 158 | |
---|
| 159 | def setUp(self): |
---|
| 160 | super(EtranzactTestsApplicants, self).setUp() |
---|
| 161 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 162 | self.browser.open(self.manage_path) |
---|
| 163 | #IWorkflowState(self.student).setState('started') |
---|
| 164 | super(EtranzactTestsApplicants, self).fill_correct_values() |
---|
| 165 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 166 | self.browser.getControl("Save").click() |
---|
| 167 | self.browser.getControl("Add online").click() |
---|
| 168 | self.assertTrue( |
---|
| 169 | 'Session configuration object is not available' |
---|
| 170 | in self.browser.contents) |
---|
| 171 | configuration = SessionConfiguration() |
---|
| 172 | configuration.academic_session = 2009 |
---|
| 173 | configuration.application_fee = 1000.0 |
---|
| 174 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
[8430] | 175 | self.browser.open(self.manage_path) |
---|
[8267] | 176 | self.browser.getControl("Add online").click() |
---|
| 177 | self.assertMatches('...ticket created...', |
---|
| 178 | self.browser.contents) |
---|
| 179 | self.assertMatches('...Amount Authorized...', |
---|
| 180 | self.browser.contents) |
---|
| 181 | self.assertMatches( |
---|
| 182 | '...<span>1000.0</span>...', |
---|
| 183 | self.browser.contents) |
---|
| 184 | self.payment_url = self.browser.url |
---|
| 185 | |
---|
| 186 | @external_test |
---|
| 187 | def test_etranzact_query_history(self): |
---|
| 188 | |
---|
[7976] | 189 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 190 | % self.CONFIRMATION_NO) |
---|
[8267] | 191 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 192 | self.browser.contents) |
---|
[8267] | 193 | #self.assertMatches('...Wrong amount...', |
---|
| 194 | # self.browser.contents) |
---|
| 195 | #self.applicant[value].amount_auth = self.applicant[ |
---|
| 196 | # value].r_amount_approved |
---|
| 197 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 198 | # % self.CONFIRMATION_NO) |
---|
| 199 | #self.assertMatches('...Wrong transaction id...', |
---|
| 200 | # self.browser.contents) |
---|