[7894] | 1 | ## $Id: tests.py 9714 2012-11-23 10:51:00Z 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 | ## |
---|
[9712] | 18 | from zope.component import getUtility |
---|
| 19 | from zope.catalog.interfaces import ICatalog |
---|
[7894] | 20 | from hurry.workflow.interfaces import IWorkflowState |
---|
| 21 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
[8266] | 22 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
| 23 | from waeup.kofa.configuration import SessionConfiguration |
---|
[8619] | 24 | from waeup.futminna.testing import FunctionalLayer |
---|
[7894] | 25 | |
---|
[7970] | 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 | |
---|
| 41 | |
---|
[8266] | 42 | class InterswitchTestsStudents(StudentsFullSetup): |
---|
[7929] | 43 | """Tests for the Interswitch payment gateway. |
---|
[7894] | 44 | """ |
---|
| 45 | |
---|
| 46 | layer = FunctionalLayer |
---|
| 47 | |
---|
[7970] | 48 | def setUp(self): |
---|
[8266] | 49 | super(InterswitchTestsStudents, self).setUp() |
---|
[7970] | 50 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
[7995] | 51 | self.browser.open(self.payments_path) |
---|
[7970] | 52 | IWorkflowState(self.student).setState('cleared') |
---|
[7995] | 53 | self.browser.open(self.payments_path + '/addop') |
---|
[9386] | 54 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
[7970] | 55 | self.browser.getControl("Create ticket").click() |
---|
[9285] | 56 | self.assertMatches('...Payment ticket created...', |
---|
[7970] | 57 | self.browser.contents) |
---|
[9285] | 58 | ctrl = self.browser.getControl(name='val_id') |
---|
| 59 | value = ctrl.options[0] |
---|
| 60 | self.browser.getLink(value).click() |
---|
[8266] | 61 | self.assertMatches('...Amount Authorized...', |
---|
| 62 | self.browser.contents) |
---|
| 63 | self.assertMatches( |
---|
[9285] | 64 | '...<span>131500.0</span>...', |
---|
[8266] | 65 | self.browser.contents) |
---|
| 66 | self.payment_url = self.browser.url |
---|
| 67 | |
---|
[9432] | 68 | def test_interswitch_form(self): |
---|
[8266] | 69 | # Manager can access InterswitchForm |
---|
| 70 | self.browser.getLink("CollegePAY", index=0).click() |
---|
[9386] | 71 | # The total amount to be processed by Interswitch |
---|
| 72 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
[8266] | 73 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 74 | self.browser.contents) |
---|
| 75 | self.assertMatches( |
---|
[9285] | 76 | '...<input type="hidden" name="amount" value="13150000.0" />...', |
---|
[8266] | 77 | self.browser.contents) |
---|
[9386] | 78 | self.assertMatches( |
---|
[9630] | 79 | '...item_name="School Fee" item_amt="12970000" bank_id="31" acct_num="0021030851"...', |
---|
[9386] | 80 | self.browser.contents) |
---|
| 81 | self.assertMatches( |
---|
[9630] | 82 | '...item_name="BT Education" item_amt="150000" bank_id="31" acct_num="0026781725"...', |
---|
[9386] | 83 | self.browser.contents) |
---|
[8266] | 84 | |
---|
[9386] | 85 | # Create clearance fee ticket |
---|
| 86 | self.browser.open(self.payments_path + '/addop') |
---|
| 87 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
| 88 | self.browser.getControl("Create ticket").click() |
---|
| 89 | self.assertMatches('...ticket created...', |
---|
| 90 | self.browser.contents) |
---|
| 91 | ctrl = self.browser.getControl(name='val_id') |
---|
| 92 | value = ctrl.options[1] |
---|
| 93 | self.browser.getLink(value).click() |
---|
| 94 | self.assertMatches('...Amount Authorized...', |
---|
| 95 | self.browser.contents) |
---|
| 96 | self.assertMatches( |
---|
[9714] | 97 | '...<span>3456.0</span>...', |
---|
[9386] | 98 | self.browser.contents) |
---|
| 99 | # Manager can access InterswitchForm |
---|
| 100 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 101 | # The total amount to be processed by Interswitch |
---|
| 102 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
| 103 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 104 | self.browser.contents) |
---|
| 105 | self.assertMatches( |
---|
[9714] | 106 | '...<input type="hidden" name="amount" value="345600.0" />...', |
---|
[9386] | 107 | self.browser.contents) |
---|
| 108 | self.assertMatches( |
---|
[9714] | 109 | '...item_name="Acceptance Fee" item_amt="315600" bank_id="120" acct_num="1750005063"...', |
---|
[9386] | 110 | self.browser.contents) |
---|
| 111 | # BT does nor charge a fee for clearance |
---|
| 112 | self.assertFalse("BT Education" in self.browser.contents) |
---|
| 113 | |
---|
[9410] | 114 | # Create hostel maintenance ticket |
---|
| 115 | self.browser.open(self.payments_path + '/addop') |
---|
| 116 | self.browser.getControl(name="form.p_category").value = ['hostel_maintenance'] |
---|
| 117 | self.browser.getControl("Create ticket").click() |
---|
[9431] | 118 | self.assertMatches('...You have not yet booked accommodation...', |
---|
| 119 | self.browser.contents) |
---|
| 120 | # Students have to book bed first |
---|
| 121 | self.browser.open(self.acco_path) |
---|
| 122 | IWorkflowState(self.student).setState('admitted') |
---|
| 123 | self.browser.getLink("Book accommodation").click() |
---|
| 124 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
| 125 | self.browser.getControl("Create bed ticket").click() |
---|
| 126 | # Bed is randomly selected but, since there is only |
---|
| 127 | # one bed for this student, we know that ... |
---|
| 128 | self.assertMatches('...Hall 1, Block A, Room 101, Bed A...', |
---|
| 129 | self.browser.contents) |
---|
| 130 | self.browser.open(self.payments_path + '/addop') |
---|
| 131 | self.browser.getControl(name="form.p_category").value = ['hostel_maintenance'] |
---|
| 132 | self.browser.getControl("Create ticket").click() |
---|
[9410] | 133 | self.assertMatches('...ticket created...', |
---|
| 134 | self.browser.contents) |
---|
| 135 | ctrl = self.browser.getControl(name='val_id') |
---|
| 136 | value = ctrl.options[2] |
---|
| 137 | self.browser.getLink(value).click() |
---|
| 138 | self.assertMatches('...Amount Authorized...', |
---|
| 139 | self.browser.contents) |
---|
| 140 | self.assertMatches( |
---|
| 141 | '...<span>10000.0</span>...', |
---|
| 142 | self.browser.contents) |
---|
| 143 | # Manager can access InterswitchForm |
---|
| 144 | self.browser.getLink("CollegePAY", index=0).click() |
---|
| 145 | # The total amount to be processed by Interswitch |
---|
| 146 | # has been reduced by the Interswitch fee of 150 Nairas |
---|
| 147 | self.assertMatches('...Total Amount Authorized:...', |
---|
| 148 | self.browser.contents) |
---|
| 149 | self.assertMatches( |
---|
| 150 | '...<input type="hidden" name="amount" value="1000000.0" />...', |
---|
| 151 | self.browser.contents) |
---|
| 152 | self.assertMatches( |
---|
| 153 | '...item_name="Hostel Maintenance Fee" item_amt="970000" bank_id="8" acct_num="2018856637"...', |
---|
| 154 | self.browser.contents) |
---|
| 155 | # BT does nor charge a fee for clearance |
---|
| 156 | self.assertFalse("BT Education" in self.browser.contents) |
---|
[9386] | 157 | |
---|
[9410] | 158 | |
---|
[8266] | 159 | @external_test |
---|
| 160 | def test_webservice(self): |
---|
| 161 | self.browser.open(self.payment_url + '/request_webservice') |
---|
| 162 | self.assertMatches('...Unsuccessful callback...', |
---|
| 163 | self.browser.contents) |
---|
[9712] | 164 | # The payment is now in state failed ... |
---|
[8266] | 165 | self.assertMatches('...<span>Failed</span>...', |
---|
[9712] | 166 | self.browser.contents) |
---|
| 167 | # ... and the catalog has been updated |
---|
| 168 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
| 169 | results = list( |
---|
| 170 | cat.searchResults(p_state=('failed', 'failed'))) |
---|
| 171 | self.assertEqual(len(results), 1) |
---|
| 172 | self.assertEqual(results[0].p_state, 'failed') |
---|