1 | ## $Id: tests.py 14740 2017-08-01 12:17:28Z 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 | ## |
---|
18 | import os |
---|
19 | import unittest |
---|
20 | from datetime import datetime, timedelta, date |
---|
21 | from zope.component import createObject, getUtility |
---|
22 | from zope.catalog.interfaces import ICatalog |
---|
23 | from hurry.workflow.interfaces import IWorkflowState |
---|
24 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
25 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
26 | from waeup.kofa.configuration import SessionConfiguration |
---|
27 | from kofacustom.nigeria.students.payments import NigeriaStudentOnlinePayment |
---|
28 | from kofacustom.nigeria.testing import FunctionalLayer |
---|
29 | |
---|
30 | from 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. |
---|
36 | EXTERNAL_TESTS = True |
---|
37 | |
---|
38 | def 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 | |
---|
49 | class HelperTests(unittest.TestCase): |
---|
50 | |
---|
51 | merchantId = '2547916' |
---|
52 | serviceTypeId = '4430731' |
---|
53 | api_key = '1946' |
---|
54 | orderId = '987698769876' |
---|
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'987698769876', |
---|
82 | u'RRR': u'320007640976 ', # 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='320007640976', |
---|
94 | host=self.host, |
---|
95 | https=False, |
---|
96 | ) |
---|
97 | assert resp == { |
---|
98 | u'orderId': u'987698769876', |
---|
99 | u'status': u'021', |
---|
100 | u'amount': 1000.0, |
---|
101 | u'transactiontime': u'2017-08-01 12:10:32 PM', |
---|
102 | u'message': u'Transaction Pending', |
---|
103 | u'lineitems': [{u'status': u'021', u'lineItemsId': u'itemid1'}, |
---|
104 | {u'status': u'021', u'lineItemsId': u'itemid2'} |
---|
105 | ], |
---|
106 | u'RRR': u'320007640976'} |
---|
107 | |
---|
108 | |
---|
109 | class RemitaTestsStudents(StudentsFullSetup): |
---|
110 | """Tests for the Remita payment gateway. |
---|
111 | """ |
---|
112 | |
---|
113 | layer = FunctionalLayer |
---|
114 | |
---|
115 | merchantId = '2547916' |
---|
116 | serviceTypeId = '4430731' |
---|
117 | api_key = '1946' |
---|
118 | orderId = '3456346346' |
---|
119 | amount = '1000' |
---|
120 | responseurl = 'http://xxxx' |
---|
121 | host = 'www.remitademo.net' |
---|
122 | |
---|
123 | def setUp(self): |
---|
124 | super(RemitaTestsStudents, self).setUp() |
---|
125 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
126 | self.browser.open(self.payments_path) |
---|
127 | IWorkflowState(self.student).setState('cleared') |
---|
128 | self.student.nationality = u'NG' |
---|
129 | self.browser.open(self.payments_path + '/addop') |
---|
130 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
131 | self.browser.getControl("Create ticket").click() |
---|
132 | self.assertMatches('...ticket created...', |
---|
133 | self.browser.contents) |
---|
134 | ctrl = self.browser.getControl(name='val_id') |
---|
135 | self.value = ctrl.options[0] |
---|
136 | self.browser.getLink(self.value).click() |
---|
137 | self.assertMatches('...Amount Authorized...', |
---|
138 | self.browser.contents) |
---|
139 | self.assertTrue('<span>40000.0</span>', self.browser.contents) |
---|
140 | self.payment_url = self.browser.url |
---|
141 | self.payment = self.student['payments'][self.value] |
---|
142 | |
---|
143 | |
---|
144 | @external_test |
---|
145 | def test_query_remita(self): |
---|
146 | # We can only test the first part of query_interswitch since |
---|
147 | # we have no succesful payment. |
---|
148 | qr = query_remita( |
---|
149 | self.payment, |
---|
150 | merchantId=self.merchantId, |
---|
151 | api_key=self.api_key, |
---|
152 | RRR='320007640976', |
---|
153 | host=self.host, |
---|
154 | https=False, |
---|
155 | verify=False) |
---|
156 | assert qr == ( |
---|
157 | False, |
---|
158 | u'Unsuccessful callback: ${a}', |
---|
159 | u'unsuccessful callback for schoolfee payment %s: Transaction Pending' |
---|
160 | % self.payment.p_id) |
---|