-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest.py
More file actions
221 lines (171 loc) · 8.14 KB
/
test.py
File metadata and controls
221 lines (171 loc) · 8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# Standard library imports
import unittest, logging
from mock import Mock, patch
import os
# Third party imports
from dotenv import load_dotenv
from nose.tools import *
# Local imports
from rave_python import Rave, RaveExceptions, Misc
from rave_python.rave_exceptions import *
load_dotenv()
# This class tests card and account payment options on Rave. It uses mock data
class TestRavePaymentOptions(unittest.TestCase):
maxDiff = None
def setUp(self):
publicKey = os.getenv("PUBLIC_KEY")
secretKey = os.getenv("SECRET_KEY")
self.rave = Rave(
publicKey,
secretKey,
production=False,
usingEnv=True
)
self.logger = logging.getLogger('test_logger')
self.logger.setLevel(logging.DEBUG)
self.logger.addHandler(logging.StreamHandler())
# def test_card_charge(self):
# # sample data
# card_details = {
# "cardno": "5531886652142950",
# "cvv": "564",
# "expirymonth": "09",
# "expiryyear": "22",
# "currency": "NGN",
# "amount": "100",
# "email": "user@example.com",
# "phonenumber": "08100000000",
# "firstname": "Test",
# "lastname": "User",
# "txRef": "mocked_test"
# }
# faulty_card_details = {
# "cardno": "5399838383838381",
# "cvv": "470",
# "expirymonth": "10",
# "currency": "NGN",
# "expiryyear": "22",
# "phonenumber": "08100000000",
# "firstname": "Test",
# "lastname": "User",
# }
# mocked_card_data_1 = {
# 'validationRequired': True,
# 'suggestedAuth': 'PIN',
# 'flwRef': None,
# 'authUrl': None,
# 'error': False,
# 'txRef': 'mocked_test'
# }
# # 1. Test case 1: successful charge initiation - should return suggested auth
# response = self.rave.Card.charge(card_details)
# self.assertEqual(response['status'], 'success')
# # 2. Test case 2: failed charge initiation - should return IncompletePaymentDetailsError
# # 3. Test case 3: successful card charge - should return 200, response.data to include []
# # 4. Test case 4: successful charge validation - should return 200, response.data to include []
# # 5. Test case 5: successful transaction verification - should return 200, response.data to include []
# def test_apple_pay_successful_charge(self):
# with patch('rave_python.rave_payment.requests.post') as mock_post:
# # mock payload
# sample_payload = {
# "amount": 10,
# "PBFPubKey": os.getenv("PUBLIC_KEY"),
# "currency": "USD",
# "email": "user@example.com",
# "meta": [{"metaname": "test", "metavalue": "12383"}],
# "ip": "123.0.1.3",
# "firstname": "Flutterwave",
# "lastname": "Tester"
# }
# mock_post.return_value = Mock(ok=True)
# mock_post.return_value.json.return_value = apple_pay_response
# response = self.rave.ApplePay.charge(sample_payload)
# self.assertEqual(response['flwRef'], apple_pay_response['data']['flwRef'])
# self.assertIsNotNone(response['authurl'])
# # self.logger.debug("Mocked Response: %s", response)
# @raises(IncompletePaymentDetailsError)
# def test_apple_pay_failed_incomplete_charge(self):
# with patch('rave_python.rave_payment.requests.post') as mock_post:
# # mock incomplete payload (missing amount)
# sample_payload = {
# "PBFPubKey": os.getenv("PUBLIC_KEY"),
# "currency": "USD",
# "email": "user@example.com",
# "meta": [{"metaname": "test", "metavalue": "12383"}],
# "ip": "123.0.1.3",
# "firstname": "Flutterwave",
# "lastname": "Tester"
# }
# mock_post.return_value = Mock(ok=True)
# mock_post.return_value.json.return_value = apple_pay_response
# response = self.rave.ApplePay.charge(sample_payload)
# def test_fawry_pay_successful_charge(self):
# with patch('rave_python.rave_payment.requests.post') as mock_post:
# # mock payload
# sample_payload = {
# "amount": 10,
# "PBFPubKey": os.getenv("PUBLIC_KEY"),
# "email": "user@example.com",
# "meta": [{"metaname": "test", "metavalue": "12383"}],
# "ip": "123.0.1.3",
# "firstname": "Flutterwave",
# "lastname": "Tester",
# "phonenumber": "233010521034"
# }
# mock_post.return_value = Mock(ok=True)
# mock_post.return_value.json.return_value = fawry_pay_response
# response = self.rave.FawryPay.charge(sample_payload)
# self.assertEqual(response['flwRef'], fawry_pay_response['data']['flwRef'])
# # self.logger.debug("Mocked Response: %s", response)
# @raises(IncompletePaymentDetailsError)
# def test_fawry_pay_failed_incomplete_charge(self):
# with patch('rave_python.rave_payment.requests.post') as mock_post:
# # mock incomplete payload (missing amount)
# sample_payload = {
# "PBFPubKey": os.getenv("PUBLIC_KEY"),
# "email": "user@example.com",
# "meta": [{"metaname": "test", "metavalue": "12383"}],
# "ip": "123.0.1.3",
# "firstname": "Flutterwave",
# "lastname": "Tester"
# }
# mock_post.return_value = Mock(ok=True)
# mock_post.return_value.json.return_value = fawry_pay_response
# response = self.rave.FawryPay.charge(sample_payload)
# def test_google_pay_successful_charge(self):
# with patch('rave_python.rave_payment.requests.post') as mock_post:
# # mock payload
# sample_payload = {
# "amount": 10,
# "PBFPubKey": os.getenv("PUBLIC_KEY"),
# "currency": "USD",
# "email": "user@example.com",
# "meta": [{"metaname": "test", "metavalue": "12383"}],
# "ip": "123.0.1.3",
# "firstname": "Flutterwave",
# "lastname": "Tester"
# }
# mock_post.return_value = Mock(ok=True)
# mock_post.return_value.json.return_value = google_pay_response
# response = self.rave.GooglePay.charge(sample_payload)
# self.assertEqual(response['flwRef'], google_pay_response['data']['flwRef'])
# self.assertIsNotNone(response['authurl'])
# # self.logger.debug("Mocked Response: %s", response)
# @raises(IncompletePaymentDetailsError)
# def test_google_pay_failed_incomplete_charge(self):
# with patch('rave_python.rave_payment.requests.post') as mock_post:
# # mock incomplete payload (missing amount)
# sample_payload = {
# "PBFPubKey": os.getenv("PUBLIC_KEY"),
# "currency": "USD",
# "email": "user@example.com",
# "meta": [{"metaname": "test", "metavalue": "12383"}],
# "ip": "123.0.1.3",
# "firstname": "Flutterwave",
# "lastname": "Tester"
# }
# mock_post.return_value = Mock(ok=True)
# mock_post.return_value.json.return_value = google_pay_response
# response = self.rave.GooglePay.charge(sample_payload)
if __name__ == '__main__':
unittest.main()