-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_api.py
More file actions
94 lines (75 loc) · 3.18 KB
/
test_api.py
File metadata and controls
94 lines (75 loc) · 3.18 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
import os
import time
from unittest import TestCase, skip
from api import BankApi
class ApiTestNewObject(TestCase):
def test_create_api_object(self):
ba = BankApi()
self.assertEqual('/ASO/TechArchitecture/grantingTickets/V02', ba.LOGIN_URL)
def test_requests_session_creation(self):
ba = BankApi()
self.assertEqual(ba.session.headers['Content-Type'], 'application/json')
class ApiTestLogin(TestCase):
def test_login_wrong_credentials_403(self):
test_user = '93847582K'
test_password = '1234'
ba = BankApi()
response_data = ba.login(test_user, test_password)
self.assertEqual(403, response_data['http-status'])
def test_login_system_credentials_200_and_saves_info(self):
user = os.environ['B_AC']
password = os.environ['B_AP']
ba = BankApi()
response_data = ba.login(user, password)
self.assertEqual('OK', response_data['authenticationState'])
# Tsec header and user id needed for every other call
self.assertTrue(ba.session.headers['tsec'])
self.assertTrue(ba.userid)
self.assertTrue(len(ba.userid) > 10)
class ApiTestTsecAndRequestFuncion(TestCase):
def setUp(self):
user = os.environ['B_AC']
password = os.environ['B_AP']
self.ba = BankApi()
self.ba.login(user, password)
def test_login_saves_current_time(self):
self.assertTrue(self.ba.last_tsec_time)
@skip('No way of testing now without w8ing 4 minutes in real life')
def test_request_refresh_tsec_if_needed(self):
old_tsec = self.ba.session.headers['tsec']
time.sleep(250)
# Make a request
self.ba.get_customer_data()
new_tsec = self.ba.session.headers['tsec']
# Expect the code to change the tsec on its own with new one
self.assertTrue(old_tsec != new_tsec)
class ApiTestGetRequests(TestCase):
def setUp(self):
user = os.environ['B_AC']
password = os.environ['B_AP']
self.ba = BankApi()
self.ba.login(user, password)
def test_get_customer_data(self):
customer_data = self.ba.get_customer_data()
self.assertTrue(customer_data['customer']['isCustomer'])
def test_get_financial_dashboard(self):
dashboard_data = self.ba.get_financial_dashboard()
self.assertTrue(dashboard_data['assetBalance']['amount'] > -1)
class ApiTestPostRequests(TestCase):
def setUp(self):
user = os.environ['B_AC']
password = os.environ['B_AP']
self.ba = BankApi()
self.ba.login(user, password)
def test_wire_transfer_simulation_same_account(self):
fd = self.ba.get_financial_dashboard()
receiver_iban = fd['positions'][0]['contract']['account']['formats']['iban']
wt_data = {
'beneficiary_iban': receiver_iban,
'beneficiary_name': 'TEST NAME',
'amount': 0.1,
'description': 'test python'
}
wt_simulation = self.ba.post_wire_transfer_simulation(wt_data)
expected_output = 'LAS CUENTAS DE CARGO Y ABONO SON IGUALES '
self.assertEqual(expected_output, wt_simulation['error-message'])