source: main/kofacustom.lpng/trunk/src/kofacustom/lpng/interswitch/tests.py @ 17232

Last change on this file since 17232 was 17232, checked in by Henrik Bettermann, 21 months ago

Change pdf logo.

  • Property svn:keywords set to Id
File size: 6.1 KB
RevLine 
[16717]1## $Id: tests.py 17232 2022-12-19 09:46:44Z henrik $
[15614]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##
18import os
19from datetime import datetime, date, timedelta
20from zope.component import createObject, getUtility
21from zope.catalog.interfaces import ICatalog
22from hurry.workflow.interfaces import IWorkflowState
23from waeup.kofa.students.tests.test_browser import StudentsFullSetup
[17223]24from waeup.kofa.students.payments import StudentOnlinePayment
[15614]25from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
26from waeup.kofa.configuration import SessionConfiguration
[17223]27from kofacustom.nigeria.interswitch.helpers import confirm_transaction
[16983]28from kofacustom.lpng.testing import FunctionalLayer
[15614]29
30# Also run tests that send requests to external servers?
31#   If you enable this, please make sure the external services
32#   do exist really and are not bothered by being spammed by a test programme.
33EXTERNAL_TESTS = False
34
35def external_test(func):
36    if not EXTERNAL_TESTS:
37        myself = __file__
38        if myself.endswith('.pyc'):
[17223]39            myself = myself[:-1]
[15614]40        print "WARNING: external tests are skipped!"
41        print "WARNING: edit %s to enable them." % myself
42        return
43    return func
44
45
46class InterswitchTestsApplicants(ApplicantsFullSetup):
47    """Tests for the Interswitch payment gateway.
48    """
49
50    layer = FunctionalLayer
51
52    def setUp(self):
53        super(InterswitchTestsApplicants, self).setUp()
54        configuration = SessionConfiguration()
55        configuration.academic_session = datetime.now().year - 2
56        self.app['configuration'].addSessionConfiguration(configuration)
57        self.configuration = configuration
58        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
59        self.browser.open(self.manage_path)
60        #IWorkflowState(self.student).setState('started')
[16997]61        self.browser.getControl(name="form.firstname").value = 'John'
62        self.browser.getControl(name="form.middlename").value = 'Anthony'
63        self.browser.getControl(name="form.lastname").value = 'Tester'
64        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
65        self.browser.getControl(name="form.sex").value = ['m']
[17011]66        self.browser.getControl(name="form.vin").value = '1234'
[16997]67        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
[15614]68        self.applicantscontainer.application_fee = 1000.0
69        self.browser.getControl(name="transition").value = ['start']
70        self.browser.getControl("Save").click()
[17223]71
72
73    def test_webcheckout_form(self):
74        self.browser.getControl("Make").click()
75        self.browser.getControl(name="form.balance_amount").value = '500'
76        self.browser.getControl(name="form.p_category").value = ['donation']
[17232]77        self.browser.getControl("Initiate").click()
[17223]78
[15614]79        self.assertMatches('...ticket created...',
80                           self.browser.contents)
[17223]81
[15614]82        self.assertMatches('...Amount Authorized...',
83                           self.browser.contents)
84        self.assertMatches(
[17223]85            '...<span>500.0</span>...',
[15614]86            self.browser.contents)
87        self.payment_url = self.browser.url
88        # Manager can access InterswitchForm
[15756]89        self.browser.getLink("Pay via Interswitch", index=0).click()
[15614]90        self.assertMatches('...Total Amount Authorized:...',
91                           self.browser.contents)
92        self.assertMatches(
93            '...<input type="hidden" name="amount" value="100000" />...',
94            self.browser.contents)
95        delta = timedelta(days=8)
96        self.applicant.values()[0].creation_date -= delta
97        self.browser.open(self.payment_url)
[15756]98        self.browser.getLink("Pay via Interswitch", index=0).click()
[15614]99        self.assertMatches(
100            '...This payment ticket is too old. Please create a new ticket...',
101            self.browser.contents)
102
[17223]103
104# WebCheckout tests
105
106    # https://webpay.interswitchng.com/collections/api/v1/gettransaction.json?merchantcode=MX76823&transactionreference=p6709347986663&amount=100
107
[15614]108    @external_test
[17223]109    def test_confirm_transaction(self):
110        host = 'webpay.interswitchng.com'
111        url = '/collections/api/v1/gettransaction.json'
112        https = True
113        merchant_code = 'MX76823'
114        payment = StudentOnlinePayment()
115        payment.p_id ='p4465649308559'
116        success, msg, log = confirm_transaction(
117            payment, merchant_code, host, url, https)
118        self.assertFalse(success)
119        self.assertTrue('Unsuccessful callback:' in msg)
120        self.assertTrue('Transaction not Found' in log)
[15614]121
[17223]122        payment.p_id ='p6709347986663'
123        payment.amount_auth = 1.0
124        success, msg, log = confirm_transaction(
125            payment, merchant_code, host, url, https)
126        self.assertTrue('Amount Inconsistency' in log)
127        payment.amount_auth = 100.0
128        success, msg, log = confirm_transaction(
129            payment, merchant_code, host, url, https)
130        self.assertEqual('Successful callback received', msg)
131        self.assertTrue(success)
132        self.assertTrue(
133            "{u'SplitAccounts': [], "
134            "u'RemittanceAmount': 0, "
135            "u'MerchantReference': u'p6709347986663', "
136            "u'PaymentReference': u'FBN|WEB|MX76823|13-12-2022|935097929|608001', "
137            "u'TransactionDate': u'2022-12-13T01:34:21', "
138            "u'RetrievalReferenceNumber': u'814212374638', "
139            "u'ResponseDescription': u'Approved by Financial Institution', "
140            "u'Amount': 10000, "
141            "u'CardNumber': u'', "
142            "u'ResponseCode': u'00', "
143            "u'BankCode': u'011'}" in log)
Note: See TracBrowser for help on using the repository browser.