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