source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/tests.py @ 9387

Last change on this file since 9387 was 9387, checked in by Henrik Bettermann, 12 years ago

Switch to test environment and setup xmp split data (with constant school fee so far).

  • Property svn:keywords set to Id
File size: 8.3 KB
RevLine 
[7894]1## $Id: tests.py 9387 2012-10-22 14:37: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##
[9387]18import grok
[7894]19from hurry.workflow.interfaces import IWorkflowState
[9387]20from zope.component import createObject
21from zope.event import notify
22from waeup.kofa.university.faculty import Faculty
23from waeup.kofa.university.department import Department
[7894]24from waeup.kofa.students.tests.test_browser import StudentsFullSetup
[8266]25from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
26from waeup.kofa.configuration import SessionConfiguration
[9347]27from waeup.kwarapoly.testing import FunctionalLayer
[7894]28
[7970]29# Also run tests that send requests to external servers?
30#   If you enable this, please make sure the external services
31#   do exist really and are not bothered by being spammed by a test programme.
[8271]32EXTERNAL_TESTS = False
[7970]33
34def external_test(func):
35    if not EXTERNAL_TESTS:
36        myself = __file__
37        if myself.endswith('.pyc'):
38            myself = myself[:-2]
39        print "WARNING: external tests are skipped!"
40        print "WARNING: edit %s to enable them." % myself
41        return
42    return func
43
44
[8266]45class InterswitchTestsStudents(StudentsFullSetup):
[7929]46    """Tests for the Interswitch payment gateway.
[7894]47    """
48
49    layer = FunctionalLayer
50
[7970]51    def setUp(self):
[8266]52        super(InterswitchTestsStudents, self).setUp()
[9387]53
54        # Create at least one Kwarapoly faculty
55        self.app['faculties']['CPGS'] = Faculty(code='CPGS')
56        self.app['faculties']['CPGS']['dep1'] = Department(code='dep1')
57        self.certificate2 = createObject('waeup.Certificate')
58        self.certificate2.code = u'CERT2'
59        self.certificate2.application_category = 'basic'
60        self.certificate2.study_mode = 'nd_ft'
61        self.certificate2.start_level = 100
62        self.certificate2.end_level = 300
63        self.app['faculties']['CPGS']['dep1'].certificates.addCertificate(
64            self.certificate2)
65        # Set study course attributes of test student
66        self.student['studycourse'].certificate = self.certificate2
67        self.student['studycourse'].current_session = 2004
68        self.student['studycourse'].entry_session = 2004
69        self.student['studycourse'].current_verdict = 'A'
70        self.student['studycourse'].current_level = 100
71        # Update the catalog
72        notify(grok.ObjectModifiedEvent(self.student))
73
[7970]74        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
[7995]75        self.browser.open(self.payments_path)
[7970]76        IWorkflowState(self.student).setState('cleared')
[7995]77        self.browser.open(self.payments_path + '/addop')
[7970]78        self.browser.getControl("Create ticket").click()
79
80
[8263]81#    def callback_url(self, payment_url, resp, apprAmt):
82#        return payment_url + (
83#            '/isw_callback?echo=' +
84#            '&resp=%s' +
85#            '&desc=Something went wrong' +
86#            '&txnRef=p1331792385335' +
87#            '&payRef=' + '&retRef=' +
88#            '&cardNum=0' +
89#            '&apprAmt=%s' +
90#            '&url=http://xyz') % (resp, apprAmt)
[7894]91
[7970]92    def test_interswitch_form(self):
[7894]93
[9370]94        # In the setup method we created the ticket
95        self.assertMatches('...ticket created...',
96                           self.browser.contents)
97        ctrl = self.browser.getControl(name='val_id')
98        value = ctrl.options[0]
99        self.browser.getLink(value).click()
100        self.assertMatches('...Amount Authorized...',
101                           self.browser.contents)
102        self.assertMatches(
[9387]103            '...<span>60980.0</span>...',
[9370]104            self.browser.contents)
105        self.payment_url = self.browser.url
106
[7894]107        # Manager can access InterswitchForm
108        self.browser.getLink("CollegePAY", index=0).click()
109        self.assertMatches('...Total Amount Authorized:...',
110                           self.browser.contents)
111        self.assertMatches(
[9387]112            '...<input type="hidden" name="amount" value="6098000.0" />...',
[7894]113            self.browser.contents)
[9129]114        self.assertMatches(
[9387]115            '...item_name="schoolfee" item_amt="5768000" bank_id="120" acct_num="1771180233"...',
[9129]116            self.browser.contents)
117        self.assertMatches(
[9387]118            '...item_name="Dalash" item_amt="180000" bank_id="117" acct_num="1013196791"...',
[9129]119            self.browser.contents)
120        self.assertMatches(
[9387]121            '...item_name="BT Education" item_amt="120000" bank_id="117" acct_num="1010764827"...',
[9129]122            self.browser.contents)
[7894]123
[8263]124#    @external_test
125#    def test_callback(self):
[7970]126
[7894]127        # Manager can call callback manually
[8263]128#        self.browser.open(self.callback_url(self.payment_url, 'XX', '300'))
129#        self.assertMatches('...Unsuccessful callback: Something went wrong...',
130#                          self.browser.contents)
131#        self.assertMatches('...Failed...',
132#                           self.browser.contents)
133#        self.browser.open(self.payment_url + '/isw_callback')
134#        self.assertMatches('...Unsuccessful callback: Incomplete query string...',
135#                          self.browser.contents)
136#        self.assertMatches('...Failed...',
137#                           self.browser.contents)
138#        self.browser.open(self.callback_url(self.payment_url, '00', '300000'))
139#        self.assertMatches('...Wrong amount...',
140#                          self.browser.contents)
141#        self.browser.open(self.callback_url(self.payment_url, '00', '4000000'))
142#        self.assertMatches('...Valid callback received...',
143#                          self.browser.contents)
[7930]144
[7970]145    @external_test
[7930]146    def test_webservice(self):
147
[7970]148        self.browser.open(self.payment_url + '/request_webservice')
[7930]149        self.assertMatches('...Unsuccessful callback...',
150                          self.browser.contents)
[8266]151        # The payment is now in state failed
152        self.assertMatches('...<span>Failed</span>...',
153                          self.browser.contents)
154
155class InterswitchTestsApplicants(ApplicantsFullSetup):
156    """Tests for the Interswitch payment gateway.
157    """
158
159    layer = FunctionalLayer
160
161    def setUp(self):
162        super(InterswitchTestsApplicants, self).setUp()
163        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
164        self.browser.open(self.manage_path)
165        #IWorkflowState(self.student).setState('started')
166        super(InterswitchTestsApplicants, self).fill_correct_values()
[8528]167        self.applicantscontainer.application_fee = 1000.0
[8266]168        self.browser.getControl(name="transition").value = ['start']
169        self.browser.getControl("Save").click()
170        self.browser.getControl("Add online").click()
171        self.assertMatches('...ticket created...',
172                           self.browser.contents)
[8281]173        #ctrl = self.browser.getControl(name='val_id')
174        #value = ctrl.options[0]
175        #self.browser.getLink(value).click()
[8266]176        self.assertMatches('...Amount Authorized...',
177                           self.browser.contents)
178        self.assertMatches(
179            '...<span>1000.0</span>...',
180            self.browser.contents)
181        self.payment_url = self.browser.url
182
183
184    def test_interswitch_form(self):
185
186        # Manager can access InterswitchForm
187        self.browser.getLink("CollegePAY", index=0).click()
188        self.assertMatches('...Total Amount Authorized:...',
189                           self.browser.contents)
190        self.assertMatches(
[8276]191            '...<input type="hidden" name="amount" value="100000.0" />...',
[8266]192            self.browser.contents)
193
194    @external_test
195    def test_webservice(self):
196
197        self.browser.open(self.payment_url + '/request_webservice')
198        self.assertMatches('...Unsuccessful callback...',
199                          self.browser.contents)
200        # The payment is now in state failed
201        self.assertMatches('...<span>Failed</span>...',
202                          self.browser.contents)
Note: See TracBrowser for help on using the repository browser.