1 | ## $Id: tests.py 15586 2019-09-12 05:27:02Z 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 | import random |
---|
21 | import json |
---|
22 | import hashlib |
---|
23 | from datetime import datetime, timedelta, date |
---|
24 | from zope.component import createObject, getUtility |
---|
25 | from zope.catalog.interfaces import ICatalog |
---|
26 | from hurry.workflow.interfaces import IWorkflowState |
---|
27 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
28 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
29 | from waeup.kofa.configuration import SessionConfiguration |
---|
30 | from kofacustom.nigeria.students.payments import NigeriaStudentOnlinePayment |
---|
31 | from kofacustom.nigeria.testing import FunctionalLayer |
---|
32 | from kofacustom.nigeria.etranzact.helpers import ( |
---|
33 | get_query_response, get_caller_response) |
---|
34 | |
---|
35 | #from kofacustom.nigeria.etranzact.helpers import (query_etranzact) |
---|
36 | |
---|
37 | # Also run tests that send requests to external servers? |
---|
38 | # If you enable this, please make sure the external services |
---|
39 | # do exist really and are not bothered by being spammed by a test programme. |
---|
40 | |
---|
41 | EXTERNAL_TESTS = True |
---|
42 | |
---|
43 | TERMINAL_ID = '0000000001' |
---|
44 | HOST = 'demo.etranzact.com' |
---|
45 | HTTPS = True |
---|
46 | SECRET_KEY = 'DEMO_KEY' |
---|
47 | LOGO_URL = 'https://iuokada.waeup.org/static_custom/iou_logo.png' |
---|
48 | |
---|
49 | def external_test(func): |
---|
50 | if not EXTERNAL_TESTS: |
---|
51 | myself = __file__ |
---|
52 | if myself.endswith('.pyc'): |
---|
53 | myself = myself[:-1] |
---|
54 | print "WARNING: external tests are skipped!" |
---|
55 | print "WARNING: edit %s to enable them." % myself |
---|
56 | return |
---|
57 | return func |
---|
58 | |
---|
59 | class HelperTests(unittest.TestCase): |
---|
60 | |
---|
61 | terminal_id = TERMINAL_ID |
---|
62 | |
---|
63 | def _create_transaction(self, transaction_id): |
---|
64 | responseurl = 'http://xxxx' |
---|
65 | amount = '4444.0' |
---|
66 | email = 'aa@aa.ng' |
---|
67 | phone = '12324' |
---|
68 | display_fullname = 'Tester' |
---|
69 | logo_url = 'http://xxxx' |
---|
70 | hashargs = amount + self.terminal_id + transaction_id \ |
---|
71 | + responseurl + 'DEMO_KEY' |
---|
72 | hashvalue = hashlib.md5(hashargs).hexdigest() |
---|
73 | response = get_caller_response(HOST, HTTPS, self.terminal_id, |
---|
74 | transaction_id, responseurl, |
---|
75 | amount, email, phone, |
---|
76 | display_fullname, hashvalue, |
---|
77 | logo_url) |
---|
78 | return response |
---|
79 | |
---|
80 | @external_test |
---|
81 | def test_query_etranzact(self): |
---|
82 | transaction_id = str(random.randint(100000000, 999999999)) |
---|
83 | response = get_query_response(HOST, self.terminal_id, |
---|
84 | transaction_id, HTTPS) |
---|
85 | self.assertEqual( |
---|
86 | response, |
---|
87 | 'Transaction with the given transaction_id (%s) not found' |
---|
88 | % transaction_id) |
---|
89 | # Okay, let's create a transaction |
---|
90 | caller_response = self._create_transaction(transaction_id) |
---|
91 | self.assertEqual(caller_response, None) |
---|
92 | # It seems that the transaction has been created but we don't get a |
---|
93 | # useful response |
---|
94 | query_response = get_query_response(HOST, self.terminal_id, |
---|
95 | transaction_id, HTTPS) |
---|
96 | self.assertEqual(query_response, '') |
---|
97 | # The same, an 'empty' response obviously means that the transaction |
---|
98 | # was found. The result was probably sent to the response_url. |
---|
99 | return |
---|
100 | |
---|
101 | class EtranzactTestsApplicants(ApplicantsFullSetup): |
---|
102 | """Tests for the Etranzact payment gateway. |
---|
103 | """ |
---|
104 | |
---|
105 | layer = FunctionalLayer |
---|
106 | |
---|
107 | def setUp(self): |
---|
108 | super(EtranzactTestsApplicants, self).setUp() |
---|
109 | configuration = SessionConfiguration() |
---|
110 | configuration.academic_session = datetime.now().year - 2 |
---|
111 | configuration.etranzact_enabled = True |
---|
112 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
113 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
114 | self.browser.open(self.manage_path) |
---|
115 | #IWorkflowState(self.student).setState('started') |
---|
116 | super(EtranzactTestsApplicants, self).fill_correct_values() |
---|
117 | self.applicantscontainer.application_fee = 1000.0 |
---|
118 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
119 | self.browser.getControl(name="transition").value = ['start'] |
---|
120 | self.browser.getControl("Save").click() |
---|
121 | self.browser.getControl("Add online").click() |
---|
122 | self.assertMatches('...ticket created...', |
---|
123 | self.browser.contents) |
---|
124 | self.payment = self.applicant.values()[0] |
---|
125 | self.payment_url = self.browser.url |
---|
126 | |
---|
127 | @external_test |
---|
128 | def test_applicant_etranzact_form(self): |
---|
129 | # Manager can access Etranzact form |
---|
130 | self.browser.getLink("Pay via eTranzact").click() |
---|
131 | self.assertTrue("Pay now" in self.browser.contents) |
---|
132 | # Means of testing end here. |
---|
133 | return |
---|
134 | |
---|
135 | |
---|