source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/tests.py @ 14738

Last change on this file since 14738 was 14737, checked in by Henrik Bettermann, 7 years ago

Add query_remita helper function with test.

  • Property svn:keywords set to Id
File size: 6.0 KB
Line 
1## $Id: tests.py 14737 2017-08-01 07:12:58Z henrik $
2##
3## Copyright (C) 2017 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
19import unittest
20from datetime import datetime, timedelta, date
21from zope.component import createObject, getUtility
22from zope.catalog.interfaces import ICatalog
23from hurry.workflow.interfaces import IWorkflowState
24from waeup.kofa.students.tests.test_browser import StudentsFullSetup
25from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
26from waeup.kofa.configuration import SessionConfiguration
27from kofacustom.nigeria.students.payments import NigeriaStudentOnlinePayment
28from kofacustom.nigeria.testing import FunctionalLayer
29
30from kofacustom.nigeria.remita.helpers import (
31    get_JSON_POST_response, get_payment_status_via_rrr, query_remita)
32
33# Also run tests that send requests to external servers?
34#   If you enable this, please make sure the external services
35#   do exist really and are not bothered by being spammed by a test programme.
36EXTERNAL_TESTS = True
37
38def external_test(func):
39    if not EXTERNAL_TESTS:
40        myself = __file__
41        if myself.endswith('.pyc'):
42            myself = myself[:-1]
43        print "WARNING: external tests are skipped!"
44        print "WARNING: edit %s to enable them." % myself
45        return
46    return func
47
48
49class HelperTests(unittest.TestCase):
50
51    merchantId = '2547916'
52    serviceTypeId = '4430731'
53    api_key = '1946'
54    orderId = '3456346346'
55    amount = '1000'
56    responseurl = 'http://xxxx'
57    host = 'www.remitademo.net'
58    lineitems = (
59                  {"lineItemsId":"itemid1","beneficiaryName":"Oshadami Mike",
60                  "beneficiaryAccount":"6020067886","bankCode":"011",
61                  "beneficiaryAmount":"500","deductFeeFrom":"1"},
62                  {"lineItemsId":"itemid2","beneficiaryName":"Ogunseye Mujib",
63                  "beneficiaryAccount":"0360883515","bankCode":"050",
64                  "beneficiaryAmount":"500","deductFeeFrom":"0"}
65                )
66
67    @external_test
68    def test_get_JSON_POST_response(self):
69
70        url = '/remita/ecomm/split/init.reg'  # /remita/ecomm/v2/init.reg
71
72        resp = get_JSON_POST_response(
73                merchantId=self.merchantId, serviceTypeId=self.serviceTypeId,
74                api_key=self.api_key, orderId=self.orderId,
75                amount=self.amount, responseurl=self.responseurl,
76                host=self.host, url=url, https=False,
77                fullname='Anton Meier', email='am@xxx.de',
78                lineitems=self.lineitems)
79        assert resp == {
80            u'status': u'RRR Already Exist for the orderId',
81            u'orderID': u'3456346346',
82            u'RRR': u'280007640804 ',  # strange trailing whitespace which
83                                       # obviously does not belong to the RRR
84            u'statuscode': u'055'}
85
86
87    @external_test
88    def test_payment_status_via_rrr(self):
89
90        resp = get_payment_status_via_rrr(
91                merchantId=self.merchantId,
92                api_key=self.api_key,
93                RRR='280007640804',
94                host=self.host,
95                https=False,
96                )
97
98        assert resp == {
99            u'orderId': u'3456346346',
100            u'status': u'021',
101            u'amount': 1000.0,
102            u'transactiontime': u'2017-07-31 11:17:24 AM',
103            u'message': u'Transaction Pending',
104            u'lineitems': [{u'status': u'021', u'lineItemsId': u'itemid1'},
105                           {u'status': u'021', u'lineItemsId': u'itemid2'}
106                          ],
107            u'RRR': u'280007640804'}
108
109
110class RemitaTestsStudents(StudentsFullSetup):
111    """Tests for the Remita payment gateway.
112    """
113
114    layer = FunctionalLayer
115
116    merchantId = '2547916'
117    serviceTypeId = '4430731'
118    api_key = '1946'
119    orderId = '3456346346'
120    amount = '1000'
121    responseurl = 'http://xxxx'
122    host = 'www.remitademo.net'
123
124    def setUp(self):
125        super(RemitaTestsStudents, self).setUp()
126        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
127        self.browser.open(self.payments_path)
128        IWorkflowState(self.student).setState('cleared')
129        self.student.nationality = u'NG'
130        self.browser.open(self.payments_path + '/addop')
131        self.browser.getControl(name="form.p_category").value = ['schoolfee']
132        self.browser.getControl("Create ticket").click()
133        self.assertMatches('...ticket created...',
134                           self.browser.contents)
135        ctrl = self.browser.getControl(name='val_id')
136        self.value = ctrl.options[0]
137        self.browser.getLink(self.value).click()
138        self.assertMatches('...Amount Authorized...',
139                           self.browser.contents)
140        self.assertTrue('<span>40000.0</span>', self.browser.contents)
141        self.payment_url = self.browser.url
142        self.payment = self.student['payments'][self.value]
143
144
145    @external_test
146    def test_query_remita(self):
147        # We can only test the first part of query_interswitch since
148        # we have no succesful payment.
149        qr = query_remita(
150            self.payment,
151            merchantId=self.merchantId,
152            api_key=self.api_key,
153            RRR='280007640804',
154            host=self.host,
155            https=False,
156            verify=False)
157        assert qr == (
158            False,
159            u'Unsuccessful callback: ${a}',
160            u'unsuccessful callback for schoolfee payment %s: Transaction Pending'
161            % self.payment.p_id)
Note: See TracBrowser for help on using the repository browser.