forked from Jake-parkers/rave-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
127 lines (111 loc) · 5.8 KB
/
test.py
File metadata and controls
127 lines (111 loc) · 5.8 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
import unittest
from python_rave import Rave, RaveExceptions, Misc
from python_rave.rave_exceptions import RaveError, IncompletePaymentDetailsError, AccountChargeError,TransactionVerificationError, TransactionValidationError, ServerError, CardChargeError
# This class tests card and account payment options on Rave. It uses mock data
class TestRavePaymentOptions(unittest.TestCase):
def setUp(self):
self.account_details = {
"accountbank":"044",
"accountnumber":"0690000031",
"amount":"500",
"country":"NG",
"email":"varisiv@gmail.com",
"phonenumber":"08031142735",
"IP":"127.0.0.1"
}
self.faulty_account_details = {
"accountbank":"044",
"accountnumber":"0690000031",
"amount":"invalid_amount",
"country":"NG",
"email":"varisiv@gmail.com",
"phonenumber":"08031142735",
"IP":"127.0.0.1"
}
self.card_details = {
"cardno": "5399838383838381",
"cvv": "470",
"expirymonth": "10",
"expiryyear": "22",
"amount": "100",
"email": "user@gmail.com",
"phonenumber": "0902620185",
"firstname": "temi",
"lastname": "desola",
"IP": "355426087298442",
}
self.faulty_card_details = {
"cardno": "5399838383838381",
"cvv": "470",
"expirymonth": "10",
"expiryyear": "22",
"phonenumber": "0902620185",
"firstname": "temi",
"lastname": "desola",
"IP": "355426087298442",
}
self.saved_card_details = {
"token":"flw-t1nf-5b0f12d565cd961f73c51370b1340f1f-m03k",
"country":"NG",
"amount":1000,
"email":"user@gmail.com",
"firstname":"temi",
"lastname":"Oyekole",
"IP":"190.233.222.1",
"txRef":"MC-7666-YU",
"currency":"NGN",
}
self.faulty_saved_card_details = {
"token":"flw-t1nf-5b0f12d565cd961f73c51370b1340f1f-m03k",
"country":"NG",
"amount":1000,
"firstname":"temi",
"lastname":"Oyekole",
"IP":"190.233.222.1",
"txRef":"MC-7666-YU",
"currency":"NGN",
}
self.rave = Rave("FLWPUBK-ba0a57153f497c03bf34a9e296aa9439-X", "FLWSECK-327b3874ca8e75640a1198a1b75c0b0b-X", usingEnv = False)
def test_account(self):
# This test case checks that on initiating a payment, the user is requested to validate the payment
res = self.rave.Account.charge(self.account_details)
self.assertEqual(res["validationRequired"], True)
with self.assertRaises(AccountChargeError):
self.rave.Account.charge(self.faulty_account_details)
# This test case checks that a user validates a transaction appropriately
self.assertEqual(self.rave.Account.validate(res["flwRef"], "12345")["error"], False)
with self.assertRaises(TransactionValidationError):
self.rave.Account.validate(res["flwRef"], "123") # a wrong otp to ensure TransactionValidationError is raised anytime a wrong otp is passed
self.assertEqual(self.rave.Account.verify(res["txRef"])["transactionComplete"], True)
with self.assertRaises(TransactionVerificationError):
self.rave.Account.verify("MC-8883838388881") # a wrong txRef to ensure TransactionVerificationError is raised anytime a wrong transaction reference is passed
def test_card(self):
res = self.rave.Card.charge(self.card_details)
self.assertIsNotNone(res["suggestedAuth"])
with self.assertRaises(IncompletePaymentDetailsError):
self.rave.Card.charge(self.faulty_card_details)
arg = Misc.getTypeOfArgsRequired(res["suggestedAuth"])
if arg == "pin":
Misc.updatePayload(res["suggestedAuth"], self.card_details, pin="3310")
if arg == "address":
Misc.updatePayload(res["suggestedAuth"], self.card_details, address= {"billingzip": "07205", "billingcity": "Hillside", "billingaddress": "470 Mundet PI", "billingstate": "NJ", "billingcountry": "US"})
res = self.rave.Card.charge(self.card_details)
# This test case checks that a user validates a transaction appropriately
self.assertEqual(res["validationRequired"], True)
self.assertEqual(self.rave.Card.validate(res["flwRef"], "12345")["error"], False)
with self.assertRaises(TransactionValidationError):
self.rave.Card.validate("FLW-MOCK-5a039c016e64da9b226c2562dcd76756", "12345") # a wrong otp to ensure TransactionValidationError is raised anytime a wrong otp is passed
self.assertEqual(self.rave.Card.verify(res["txRef"])["transactionComplete"], True)
with self.assertRaises(TransactionVerificationError):
self.rave.Card.verify("MC-8883838388881") # a wrong txRef to ensure TransactionVerificationError is raised anytime a wrong transaction reference is passed
def test_saved_card(self):
res = self.rave.Card.charge(self.saved_card_details, chargeWithToken=True)
self.assertIsNotNone(res["status"])
self.assertEqual(res["status"], 'success')
with self.assertRaises(IncompletePaymentDetailsError):
self.rave.Card.charge(self.faulty_saved_card_details, chargeWithToken=True)
self.assertEqual(self.rave.Card.verify(res["txRef"])["transactionComplete"], True)
with self.assertRaises(TransactionVerificationError):
self.rave.Card.verify("MC-8883838388881") # a wrong txRef to ensure TransactionVerificationError is raised anytime a wrong transaction reference is passed
if __name__ == '__main__':
unittest.main()