[7929] | 1 | ## $Id: tests.py 10937 2014-01-16 15:46:17Z 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 |
---|
[7929] | 23 | |
---|
[7970] | 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. |
---|
[8271] | 28 | EXTERNAL_TESTS = False |
---|
[7970] | 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 | |
---|
[8267] | 40 | class EtranzactTestsStudent(StudentsFullSetup): |
---|
[7976] | 41 | """Tests for the eTranzact payment gateway. |
---|
[7929] | 42 | """ |
---|
| 43 | |
---|
| 44 | layer = FunctionalLayer |
---|
| 45 | |
---|
| 46 | CONFIRMATION_NO = '500856521315472785095' |
---|
| 47 | |
---|
[7976] | 48 | def setUp(self): |
---|
[8267] | 49 | super(EtranzactTestsStudent, self).setUp() |
---|
[7929] | 50 | # Managers can add online payment tickets |
---|
| 51 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[9905] | 52 | self.app['configuration']['2004'].school_fee = 1234.0 |
---|
[7995] | 53 | self.browser.open(self.payments_path) |
---|
[7929] | 54 | IWorkflowState(self.student).setState('cleared') |
---|
[7995] | 55 | self.browser.open(self.payments_path + '/addop') |
---|
[9905] | 56 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
[7929] | 57 | self.browser.getControl("Create ticket").click() |
---|
| 58 | self.assertMatches('...ticket created...', |
---|
| 59 | self.browser.contents) |
---|
[8754] | 60 | |
---|
[7929] | 61 | ctrl = self.browser.getControl(name='val_id') |
---|
| 62 | value = ctrl.options[0] |
---|
[8731] | 63 | self.p_id = value |
---|
[7929] | 64 | self.browser.getLink(value).click() |
---|
| 65 | self.assertMatches('...Amount Authorized...', |
---|
| 66 | self.browser.contents) |
---|
[7976] | 67 | self.payment_url = self.browser.url |
---|
| 68 | |
---|
| 69 | def test_enterpin(self): |
---|
| 70 | self.browser.getLink("Query eTranzact History").click() |
---|
| 71 | self.assertMatches( |
---|
| 72 | '...Confirmation Number (PIN):...', |
---|
| 73 | self.browser.contents) |
---|
| 74 | |
---|
[8731] | 75 | def test_webservice(self): |
---|
[10937] | 76 | self.browser.open( |
---|
| 77 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=SCHOOL-FEE' |
---|
| 78 | % self.p_id) |
---|
[8731] | 79 | self.assertEqual(self.browser.contents, |
---|
[10907] | 80 | # Version 1 |
---|
| 81 | #'FULL_NAME=Anna Tester&' |
---|
| 82 | #'FACULTY=fac1&' |
---|
| 83 | #'DEPARTMENT=dep1&' |
---|
| 84 | #'RETURN_TYPE=%s&' |
---|
| 85 | #'PROGRAMME_TYPE=CERT1&' |
---|
| 86 | #'PAYMENT_TYPE=School Fee&' |
---|
| 87 | #'ACADEMIC_SESSION=2004/2005&' |
---|
| 88 | #'MATRIC_NO=E1000000&' |
---|
| 89 | #'FEE_AMOUNT=1234.0&' |
---|
| 90 | #'TRANSACTION_STATUS=unpaid' |
---|
| 91 | |
---|
| 92 | # Version 2 |
---|
| 93 | 'PayeeName=Anna Tester~' |
---|
| 94 | 'Faculty=fac1~' |
---|
| 95 | 'Department=dep1~' |
---|
| 96 | 'Level=100~' |
---|
| 97 | 'ProgrammeType=CERT1~' |
---|
| 98 | 'StudyType=ug_ft~' |
---|
| 99 | 'Session=2004/2005~' |
---|
| 100 | 'PayeeID=%s~' |
---|
| 101 | 'Amount=1234.0~' |
---|
| 102 | 'FeeStatus=unpaid~' |
---|
[10932] | 103 | 'Semester=N/A~' |
---|
[10907] | 104 | 'PaymentType=School Fee~' |
---|
| 105 | 'MatricNumber=E1000000~' |
---|
| 106 | 'Email=aa@aa.ng~' |
---|
| 107 | 'PhoneNumber=1234' % self.p_id) |
---|
| 108 | |
---|
[10937] | 109 | self.browser.open('http://localhost/app/feerequest') |
---|
| 110 | self.assertEqual(self.browser.contents, '-1') |
---|
[9508] | 111 | self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense') |
---|
| 112 | self.assertEqual(self.browser.contents, '-1') |
---|
[10937] | 113 | self.browser.open( |
---|
| 114 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=NONSENSE' |
---|
| 115 | % self.p_id) |
---|
| 116 | self.assertEqual(self.browser.contents, '-3') |
---|
| 117 | self.browser.open( |
---|
| 118 | 'http://localhost/app/feerequest?PAYEE_ID=%s' |
---|
| 119 | % self.p_id) |
---|
| 120 | self.assertEqual(self.browser.contents, '-3') |
---|
| 121 | self.browser.open( |
---|
| 122 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=ACCEPTANCE-FEE' |
---|
| 123 | % self.p_id) |
---|
| 124 | self.assertEqual(self.browser.contents, '-6') |
---|
| 125 | self.browser.open( |
---|
| 126 | 'http://localhost/app/feerequest?PAYEE_ID=%s&PAYMENT_TYPE=APPLICATION-FEE' |
---|
| 127 | % self.p_id) |
---|
| 128 | self.assertEqual(self.browser.contents, '-7') |
---|
[8731] | 129 | |
---|
[10937] | 130 | |
---|
[7976] | 131 | @external_test |
---|
| 132 | def test_etranzact_query_history(self): |
---|
| 133 | |
---|
| 134 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 135 | % self.CONFIRMATION_NO) |
---|
[8267] | 136 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 137 | self.browser.contents) |
---|
[8267] | 138 | #self.assertMatches('...Wrong amount...', |
---|
| 139 | # self.browser.contents) |
---|
| 140 | #self.student['payments'][value].amount_auth = self.student[ |
---|
| 141 | # 'payments'][value].r_amount_approved |
---|
| 142 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 143 | # % self.CONFIRMATION_NO) |
---|
| 144 | #self.assertMatches('...Wrong transaction id...', |
---|
| 145 | # self.browser.contents) |
---|
[7929] | 146 | |
---|
[8267] | 147 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
---|
| 148 | """Tests for the Interswitch payment gateway. |
---|
| 149 | """ |
---|
| 150 | |
---|
| 151 | layer = FunctionalLayer |
---|
| 152 | |
---|
| 153 | CONFIRMATION_NO = '500856521315472785095' |
---|
| 154 | |
---|
| 155 | def setUp(self): |
---|
| 156 | super(EtranzactTestsApplicants, self).setUp() |
---|
| 157 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 158 | self.browser.open(self.manage_path) |
---|
| 159 | #IWorkflowState(self.student).setState('started') |
---|
| 160 | super(EtranzactTestsApplicants, self).fill_correct_values() |
---|
| 161 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 162 | self.browser.getControl("Save").click() |
---|
| 163 | self.browser.getControl("Add online").click() |
---|
| 164 | self.assertTrue( |
---|
| 165 | 'Session configuration object is not available' |
---|
| 166 | in self.browser.contents) |
---|
| 167 | configuration = SessionConfiguration() |
---|
| 168 | configuration.academic_session = 2009 |
---|
| 169 | configuration.application_fee = 1000.0 |
---|
| 170 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
[8430] | 171 | self.browser.open(self.manage_path) |
---|
[8267] | 172 | self.browser.getControl("Add online").click() |
---|
| 173 | self.assertMatches('...ticket created...', |
---|
| 174 | self.browser.contents) |
---|
| 175 | self.assertMatches('...Amount Authorized...', |
---|
| 176 | self.browser.contents) |
---|
| 177 | self.assertMatches( |
---|
| 178 | '...<span>1000.0</span>...', |
---|
| 179 | self.browser.contents) |
---|
| 180 | self.payment_url = self.browser.url |
---|
| 181 | |
---|
| 182 | @external_test |
---|
| 183 | def test_etranzact_query_history(self): |
---|
| 184 | |
---|
[7976] | 185 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 186 | % self.CONFIRMATION_NO) |
---|
[8267] | 187 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 188 | self.browser.contents) |
---|
[8267] | 189 | #self.assertMatches('...Wrong amount...', |
---|
| 190 | # self.browser.contents) |
---|
| 191 | #self.applicant[value].amount_auth = self.applicant[ |
---|
| 192 | # value].r_amount_approved |
---|
| 193 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 194 | # % self.CONFIRMATION_NO) |
---|
| 195 | #self.assertMatches('...Wrong transaction id...', |
---|
| 196 | # self.browser.contents) |
---|