1 | ## $Id: tests.py 17223 2022-12-13 21:15:18Z 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 | ## |
---|
18 | import os |
---|
19 | from datetime import datetime, date, timedelta |
---|
20 | from zope.component import createObject, getUtility |
---|
21 | from zope.catalog.interfaces import ICatalog |
---|
22 | from hurry.workflow.interfaces import IWorkflowState |
---|
23 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
24 | from waeup.kofa.students.payments import StudentOnlinePayment |
---|
25 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
26 | from waeup.kofa.configuration import SessionConfiguration |
---|
27 | from kofacustom.nigeria.interswitch.helpers import confirm_transaction |
---|
28 | from 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. |
---|
33 | EXTERNAL_TESTS = False |
---|
34 | |
---|
35 | def 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 | |
---|
46 | class 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') |
---|
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'] |
---|
66 | self.browser.getControl(name="form.vin").value = '1234' |
---|
67 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
68 | self.applicantscontainer.application_fee = 1000.0 |
---|
69 | self.browser.getControl(name="transition").value = ['start'] |
---|
70 | self.browser.getControl("Save").click() |
---|
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'] |
---|
77 | self.browser.getControl("Create").click() |
---|
78 | |
---|
79 | self.assertMatches('...ticket created...', |
---|
80 | self.browser.contents) |
---|
81 | |
---|
82 | self.assertMatches('...Amount Authorized...', |
---|
83 | self.browser.contents) |
---|
84 | self.assertMatches( |
---|
85 | '...<span>500.0</span>...', |
---|
86 | self.browser.contents) |
---|
87 | self.payment_url = self.browser.url |
---|
88 | # Manager can access InterswitchForm |
---|
89 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
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) |
---|
98 | self.browser.getLink("Pay via Interswitch", index=0).click() |
---|
99 | self.assertMatches( |
---|
100 | '...This payment ticket is too old. Please create a new ticket...', |
---|
101 | self.browser.contents) |
---|
102 | |
---|
103 | |
---|
104 | # WebCheckout tests |
---|
105 | |
---|
106 | # https://webpay.interswitchng.com/collections/api/v1/gettransaction.json?merchantcode=MX76823&transactionreference=p6709347986663&amount=100 |
---|
107 | |
---|
108 | @external_test |
---|
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) |
---|
121 | |
---|
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) |
---|