-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
124 lines (105 loc) · 4.38 KB
/
tests.py
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
#!/usr/bin/python
# coding: utf-8
import unittest
import os
from konduto import Konduto
from konduto.models import Order
from konduto.models import Customer
from konduto.models import Payment
from konduto.utils import *
from random import randint
import logging
# Load .env variables
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv(), override=True)
KONDUTO_PUBLIC_KEY = os.getenv('KONDUTO_PUBLIC_KEY')
KONDUTO_PRIVATE_KEY = os.getenv('KONDUTO_PRIVATE_KEY')
class KondutoTestCase(unittest.TestCase):
unique_id = None
def setUp(self):
self.konduto = Konduto(KONDUTO_PUBLIC_KEY, KONDUTO_PRIVATE_KEY)
def _build_simple_customer(self, info=None):
return Customer(**{
"id": "28372",
"name": "Júlia da Silva",
"tax_id": "12345678909",
"dob": "1970-12-25",
"phone1": "11-1234-5678",
"phone2": "21-2143-6578",
"email": "jsilva@exemplo.com.br",
"created_at": "2010-12-25",
"new": False,
"vip": False})
def _build_simple_payment(self, info=None):
return Payment(**{
"type": "credit",
"bin": "490172",
"last4": "0012",
"expiration_date": "072015",
"status": "approved"})
def _build_simple_order(self, info=None):
self.unique_id = str(randint(1, 100000))
customer = self._build_simple_customer()
payment = self._build_simple_payment()
order_json = {
"id": self.unique_id,
"visitor": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"total_amount": 100.01, # Result approve in test env
"shipping_amount": 20.00,
"tax_amount": 3.45,
"currency": "BRL",
"installments": 2,
"ip": "189.68.156.100",
"customer": customer,
"payment": payment,
}
if info is not None:
order_json.update(info)
order = Order(**order_json)
return order
def _assert_order1_fields(self, order):
self.assertEqual(self.unique_id, order.id)
self.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", order.visitor)
self.assertEqual(100.01, order.total_amount)
self.assertEqual(20.0, order.shipping_amount)
self.assertEqual(3.45, order.tax_amount)
self.assertEqual("BRL", order.currency)
self.assertEqual(2, order.installments)
self.assertEqual("189.68.156.100", order.ip)
self.assertIsInstance(order.customer, Customer)
customer = order.customer
self.assertEqual("28372", customer.id)
self.assertEqual("Júlia da Silva", customer.name)
self.assertEqual("12345678909", customer.tax_id)
#self.assertDate("1970-12-25", customer.getDob())
self.assertEqual("11-1234-5678", customer.phone1)
self.assertEqual("21-2143-6578", customer.phone2)
self.assertEqual("jsilva@exemplo.com.br", customer.email)
#self.assertDate("2010-12-25", customer.getCreatedAt())
self.assertFalse(customer.new)
self.assertFalse(customer.vip)
#self.assertOrderResponse(order, "APPROVE", 0.01)
payment = order.payment
self.assertEqual("credit", payment.type)
self.assertEqual("490172", payment.bin)
self.assertEqual("0012", payment.last4)
self.assertEqual("072015", payment.expiration_date)
self.assertEqual("approved", payment.status)
def test_expect_recommendation_approve(self):
order = self._build_simple_order()
response = self.konduto.analyze(order)
self.assertEqual(response.recommendation, RECOMMENDATION_APPROVE)
def test_expect_recommendation_review(self):
order = self._build_simple_order({"total_amount": 100.31})
response = self.konduto.analyze(order)
self.assertEqual(response.recommendation, RECOMMENDATION_REVIEW)
def test_expect_recommendation_decline(self):
order = self._build_simple_order({"total_amount": 100.61})
response = self.konduto.analyze(order)
self.assertEqual(response.recommendation, RECOMMENDATION_DECLINE)
def test_assert_all_fields(self):
order = self._build_simple_order()
order = self.konduto.analyze(order)
self._assert_order1_fields(order)
if __name__ == '__main__':
unittest.main()