-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtests.py
More file actions
87 lines (77 loc) · 3.31 KB
/
tests.py
File metadata and controls
87 lines (77 loc) · 3.31 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
import unittest
from decimal import Decimal
from cielo import GetAuthorizedException, PaymentAttempt, CreditCardToken
class MainTest(unittest.TestCase):
def test_payment_attempt_authorized(self):
params = {
'affiliation_id': '1006993069',
'api_key': '25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3',
'card_type': PaymentAttempt.VISA,
'total': Decimal('1.00'), # when amount ends with .00 attempt is automatically authorized
'order_id': '7DSD163AH1', # strings are allowed here
'card_number': '4012001037141112',
'cvc2': 423,
'exp_month': 1,
'exp_year': 2010,
'card_holders_name': 'JOAO DA SILVA',
'installments': 1,
'transaction': PaymentAttempt.CASH,
'sandbox': True,
}
attempt = PaymentAttempt(**params)
self.assertTrue(attempt.get_authorized())
def test_payment_attempt_unauthorized(self):
params = {
'affiliation_id': '1006993069',
'api_key': '25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3',
'card_type': PaymentAttempt.VISA,
'total': Decimal('1.01'), # when amount does not end with .00 attempt is automatically cancelled
'order_id': '7DSD63A1H1', # strings are allowed here
'card_number': '4012001037141112',
'cvc2': 423,
'exp_month': 1,
'exp_year': 2010,
'card_holders_name': 'JOAO DA SILVA',
'installments': 1,
'transaction': PaymentAttempt.CASH,
'sandbox': True,
}
attempt = PaymentAttempt(**params)
self.assertRaises(GetAuthorizedException, attempt.get_authorized)
def test_payment_attempt_capture(self):
params = {
'affiliation_id': '1006993069',
'api_key': '25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3',
'card_type': PaymentAttempt.VISA,
'total': Decimal('1.00'), # when amount ends with .00 attempt is automatically authorized
'order_id': '7DSD163AH1', # strings are allowed here
'card_number': '4012001037141112',
'cvc2': 423,
'exp_month': 1,
'exp_year': 2010,
'card_holders_name': 'JOAO DA SILVA',
'installments': 1,
'transaction': PaymentAttempt.CASH,
'sandbox': True,
}
attempt = PaymentAttempt(**params)
self.assertTrue(attempt.get_authorized())
self.assertTrue(attempt.capture())
# self.assertRaises(GetAuthorizedException, attempt.get_authorized)
def test_credit_card_token_creation(self):
params = {
'affiliation_id': '1006993069',
'api_key': '25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3',
'card_number': '4012001037141112',
'exp_month': 1,
'exp_year': 2010,
'card_holders_name': 'JOAO DA SILVA',
'sandbox': True,
}
cc_token = CreditCardToken(**params)
self.assertEqual(cc_token.create(), {
'token': 'O/sN7IgUNo4FKXy6SeQRc+BbuZiFvYo4Sqdph0EWaoI=',
'truncated': '401200******1112',
})
if __name__ == '__main__':
unittest.main()