## $Id: tests.py 14740 2017-08-01 12:17:28Z henrik $ ## ## Copyright (C) 2017 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## import os import unittest from datetime import datetime, timedelta, date from zope.component import createObject, getUtility from zope.catalog.interfaces import ICatalog from hurry.workflow.interfaces import IWorkflowState from waeup.kofa.students.tests.test_browser import StudentsFullSetup from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup from waeup.kofa.configuration import SessionConfiguration from kofacustom.nigeria.students.payments import NigeriaStudentOnlinePayment from kofacustom.nigeria.testing import FunctionalLayer from kofacustom.nigeria.remita.helpers import ( get_JSON_POST_response, get_payment_status_via_rrr, query_remita) # Also run tests that send requests to external servers? # If you enable this, please make sure the external services # do exist really and are not bothered by being spammed by a test programme. EXTERNAL_TESTS = True def external_test(func): if not EXTERNAL_TESTS: myself = __file__ if myself.endswith('.pyc'): myself = myself[:-1] print "WARNING: external tests are skipped!" print "WARNING: edit %s to enable them." % myself return return func class HelperTests(unittest.TestCase): merchantId = '2547916' serviceTypeId = '4430731' api_key = '1946' orderId = '987698769876' amount = '1000' responseurl = 'http://xxxx' host = 'www.remitademo.net' lineitems = ( {"lineItemsId":"itemid1","beneficiaryName":"Oshadami Mike", "beneficiaryAccount":"6020067886","bankCode":"011", "beneficiaryAmount":"500","deductFeeFrom":"1"}, {"lineItemsId":"itemid2","beneficiaryName":"Ogunseye Mujib", "beneficiaryAccount":"0360883515","bankCode":"050", "beneficiaryAmount":"500","deductFeeFrom":"0"} ) @external_test def test_get_JSON_POST_response(self): url = '/remita/ecomm/split/init.reg' # /remita/ecomm/v2/init.reg resp = get_JSON_POST_response( merchantId=self.merchantId, serviceTypeId=self.serviceTypeId, api_key=self.api_key, orderId=self.orderId, amount=self.amount, responseurl=self.responseurl, host=self.host, url=url, https=False, fullname='Anton Meier', email='am@xxx.de', lineitems=self.lineitems) assert resp == { u'status': u'RRR Already Exist for the orderId', u'orderID': u'987698769876', u'RRR': u'320007640976 ', # strange trailing whitespace which # obviously does not belong to the RRR u'statuscode': u'055'} @external_test def test_payment_status_via_rrr(self): resp = get_payment_status_via_rrr( merchantId=self.merchantId, api_key=self.api_key, RRR='320007640976', host=self.host, https=False, ) assert resp == { u'orderId': u'987698769876', u'status': u'021', u'amount': 1000.0, u'transactiontime': u'2017-08-01 12:10:32 PM', u'message': u'Transaction Pending', u'lineitems': [{u'status': u'021', u'lineItemsId': u'itemid1'}, {u'status': u'021', u'lineItemsId': u'itemid2'} ], u'RRR': u'320007640976'} class RemitaTestsStudents(StudentsFullSetup): """Tests for the Remita payment gateway. """ layer = FunctionalLayer merchantId = '2547916' serviceTypeId = '4430731' api_key = '1946' orderId = '3456346346' amount = '1000' responseurl = 'http://xxxx' host = 'www.remitademo.net' def setUp(self): super(RemitaTestsStudents, self).setUp() self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') self.browser.open(self.payments_path) IWorkflowState(self.student).setState('cleared') self.student.nationality = u'NG' self.browser.open(self.payments_path + '/addop') self.browser.getControl(name="form.p_category").value = ['schoolfee'] self.browser.getControl("Create ticket").click() self.assertMatches('...ticket created...', self.browser.contents) ctrl = self.browser.getControl(name='val_id') self.value = ctrl.options[0] self.browser.getLink(self.value).click() self.assertMatches('...Amount Authorized...', self.browser.contents) self.assertTrue('40000.0', self.browser.contents) self.payment_url = self.browser.url self.payment = self.student['payments'][self.value] @external_test def test_query_remita(self): # We can only test the first part of query_interswitch since # we have no succesful payment. qr = query_remita( self.payment, merchantId=self.merchantId, api_key=self.api_key, RRR='320007640976', host=self.host, https=False, verify=False) assert qr == ( False, u'Unsuccessful callback: ${a}', u'unsuccessful callback for schoolfee payment %s: Transaction Pending' % self.payment.p_id)