[7929] | 1 | ## $Id: tests.py 9755 2012-12-01 10:05:53Z 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') |
---|
[8754] | 52 | self.app['configuration']['2004'].school_fee_base = 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') |
---|
[9755] | 56 | self.browser.getControl(name="form.p_category").value = ['schoolfee_1'] |
---|
[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): |
---|
| 76 | self.browser.open('http://localhost/app/feerequest?PAYEE_ID=%s' % self.p_id) |
---|
| 77 | self.assertEqual(self.browser.contents, |
---|
[8733] | 78 | 'FULL_NAME=Anna Tester&' |
---|
| 79 | 'FACULTY=fac1&' |
---|
| 80 | 'DEPARTMENT=dep1&' |
---|
| 81 | 'RETURN_TYPE=%s&' |
---|
| 82 | 'PROGRAMME_TYPE=CERT1&' |
---|
[8754] | 83 | 'PAYMENT_TYPE=School Fee 1st instalment&' |
---|
[8733] | 84 | 'ACADEMIC_SESSION=2004/2005&' |
---|
| 85 | 'MATRIC_NO=E1000000&' |
---|
[8754] | 86 | 'FEE_AMOUNT=1234.0&' |
---|
[8733] | 87 | 'TRANSACTION_STATUS=unpaid' % self.p_id) |
---|
[9508] | 88 | self.browser.open('http://localhost/app/feerequest?NONSENSE=nonsense') |
---|
| 89 | self.assertEqual(self.browser.contents, '-1') |
---|
[8731] | 90 | |
---|
[7976] | 91 | @external_test |
---|
| 92 | def test_etranzact_query_history(self): |
---|
| 93 | |
---|
| 94 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 95 | % self.CONFIRMATION_NO) |
---|
[8267] | 96 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 97 | self.browser.contents) |
---|
[8267] | 98 | #self.assertMatches('...Wrong amount...', |
---|
| 99 | # self.browser.contents) |
---|
| 100 | #self.student['payments'][value].amount_auth = self.student[ |
---|
| 101 | # 'payments'][value].r_amount_approved |
---|
| 102 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 103 | # % self.CONFIRMATION_NO) |
---|
| 104 | #self.assertMatches('...Wrong transaction id...', |
---|
| 105 | # self.browser.contents) |
---|
[7929] | 106 | |
---|
[8267] | 107 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
---|
| 108 | """Tests for the Interswitch payment gateway. |
---|
| 109 | """ |
---|
| 110 | |
---|
| 111 | layer = FunctionalLayer |
---|
| 112 | |
---|
| 113 | CONFIRMATION_NO = '500856521315472785095' |
---|
| 114 | |
---|
| 115 | def setUp(self): |
---|
| 116 | super(EtranzactTestsApplicants, self).setUp() |
---|
| 117 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 118 | self.browser.open(self.manage_path) |
---|
| 119 | #IWorkflowState(self.student).setState('started') |
---|
| 120 | super(EtranzactTestsApplicants, self).fill_correct_values() |
---|
| 121 | self.browser.getControl(name="transition").value = ['start'] |
---|
| 122 | self.browser.getControl("Save").click() |
---|
| 123 | self.browser.getControl("Add online").click() |
---|
| 124 | self.assertTrue( |
---|
| 125 | 'Session configuration object is not available' |
---|
| 126 | in self.browser.contents) |
---|
| 127 | configuration = SessionConfiguration() |
---|
| 128 | configuration.academic_session = 2009 |
---|
| 129 | configuration.application_fee = 1000.0 |
---|
| 130 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
[8430] | 131 | self.browser.open(self.manage_path) |
---|
[8267] | 132 | self.browser.getControl("Add online").click() |
---|
| 133 | self.assertMatches('...ticket created...', |
---|
| 134 | self.browser.contents) |
---|
| 135 | self.assertMatches('...Amount Authorized...', |
---|
| 136 | self.browser.contents) |
---|
| 137 | self.assertMatches( |
---|
| 138 | '...<span>1000.0</span>...', |
---|
| 139 | self.browser.contents) |
---|
| 140 | self.payment_url = self.browser.url |
---|
| 141 | |
---|
| 142 | @external_test |
---|
| 143 | def test_etranzact_query_history(self): |
---|
| 144 | |
---|
[7976] | 145 | self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
[7929] | 146 | % self.CONFIRMATION_NO) |
---|
[8267] | 147 | self.assertMatches('...Invalid or unsuccessful callback:...', |
---|
[7929] | 148 | self.browser.contents) |
---|
[8267] | 149 | #self.assertMatches('...Wrong amount...', |
---|
| 150 | # self.browser.contents) |
---|
| 151 | #self.applicant[value].amount_auth = self.applicant[ |
---|
| 152 | # value].r_amount_approved |
---|
| 153 | #self.browser.open(self.payment_url + '/query_history?confirmation_number=%s' |
---|
| 154 | # % self.CONFIRMATION_NO) |
---|
| 155 | #self.assertMatches('...Wrong transaction id...', |
---|
| 156 | # self.browser.contents) |
---|