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

Last change on this file was 17254, checked in by Henrik Bettermann, 23 months ago

Implement Paypal module.

  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1## $Id: tests.py 17254 2022-12-30 09:25:50Z 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##
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
24from waeup.kofa.students.payments import StudentOnlinePayment
25from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
26from waeup.kofa.configuration import SessionConfiguration
27from kofacustom.nigeria.interswitch.helpers import confirm_transaction
28from kofacustom.lpng.testing import FunctionalLayer
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'):
39            myself = myself[:-1]
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        configuration.interswitch_webcheckout_enabled = True
57        self.app['configuration'].addSessionConfiguration(configuration)
58        self.configuration = configuration
59        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
60        self.browser.open(self.manage_path)
61        #IWorkflowState(self.student).setState('started')
62        self.browser.getControl(name="form.firstname").value = 'John'
63        self.browser.getControl(name="form.middlename").value = 'Anthony'
64        self.browser.getControl(name="form.lastname").value = 'Tester'
65        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
66        self.browser.getControl(name="form.sex").value = ['m']
67        self.browser.getControl(name="form.vin").value = '1234'
68        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
69        self.applicantscontainer.application_fee = 1000.0
70        self.browser.getControl(name="transition").value = ['start']
71        self.browser.getControl("Save").click()
72
73
74    def test_webcheckout_form(self):
75        self.browser.getControl("Make").click()
76        self.browser.getControl(name="form.balance_amount").value = '500'
77        self.browser.getControl(name="form.p_category").value = ['donation']
78        self.browser.getControl(name="form.p_option").value = ['NGN']
79        self.browser.getControl("Create ticket").click()
80
81        self.assertMatches('...ticket created...',
82                           self.browser.contents)
83
84        self.assertMatches('...Amount Authorized...',
85                           self.browser.contents)
86        self.assertMatches(
87            '...<span>500.0</span>...',
88            self.browser.contents)
89        self.payment_url = self.browser.url
90        # Manager can access InterswitchForm
91        self.browser.getLink("Pay via Interswitch", index=0).click()
92        self.assertMatches('...Total Amount Authorized:...',
93                           self.browser.contents)
94        self.assertMatches(
95            '...<input type="hidden" name="amount" value="100000" />...',
96            self.browser.contents)
97        delta = timedelta(days=8)
98        self.applicant.values()[0].creation_date -= delta
99        self.browser.open(self.payment_url)
100        self.browser.getLink("Pay via Interswitch", index=0).click()
101        self.assertMatches(
102            '...This payment ticket is too old. Please create a new ticket...',
103            self.browser.contents)
104
105
106# WebCheckout tests
107
108    # https://webpay.interswitchng.com/collections/api/v1/gettransaction.json?merchantcode=MX76823&transactionreference=p6709347986663&amount=100
109
110    @external_test
111    def test_confirm_transaction(self):
112        host = 'webpay.interswitchng.com'
113        url = '/collections/api/v1/gettransaction.json'
114        https = True
115        merchant_code = 'MX76823'
116        payment = StudentOnlinePayment()
117        payment.p_id ='p4465649308559'
118        success, msg, log = confirm_transaction(
119            payment, merchant_code, host, url, https)
120        self.assertFalse(success)
121        self.assertTrue('Unsuccessful callback:' in msg)
122        self.assertTrue('Transaction not Found' in log)
123
124        payment.p_id ='p6709347986663'
125        payment.amount_auth = 1.0
126        success, msg, log = confirm_transaction(
127            payment, merchant_code, host, url, https)
128        self.assertTrue('Amount Inconsistency' in log)
129        payment.amount_auth = 100.0
130        success, msg, log = confirm_transaction(
131            payment, merchant_code, host, url, https)
132        self.assertEqual('Successful callback received', msg)
133        self.assertTrue(success)
134        self.assertTrue(
135            "{u'SplitAccounts': [], "
136            "u'RemittanceAmount': 0, "
137            "u'MerchantReference': u'p6709347986663', "
138            "u'PaymentReference': u'FBN|WEB|MX76823|13-12-2022|935097929|608001', "
139            "u'TransactionDate': u'2022-12-13T01:34:21', "
140            "u'RetrievalReferenceNumber': u'814212374638', "
141            "u'ResponseDescription': u'Approved by Financial Institution', "
142            "u'Amount': 10000, "
143            "u'CardNumber': u'', "
144            "u'ResponseCode': u'00', "
145            "u'BankCode': u'011'}" in log)
Note: See TracBrowser for help on using the repository browser.