|
1
|
|
|
try: # pragma: no cover |
|
2
|
|
|
from unittest.mock import patch |
|
3
|
|
|
except ImportError: # pragma: no cover |
|
4
|
|
|
from mock import patch |
|
5
|
|
|
import besepa |
|
6
|
|
|
from besepa.resource import Resource |
|
7
|
|
|
|
|
8
|
|
|
besepa.configure(api_key='dummy') |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class TestResource(object): |
|
12
|
|
|
|
|
13
|
|
|
@patch('customers_test.besepa.Api.get', autospec=True) |
|
14
|
|
|
def test_path(self, mock): |
|
15
|
|
|
customers = besepa.Customer.all() |
|
16
|
|
|
|
|
17
|
|
|
mock.assert_called_once_with(customers.api, 'api/1/customers') |
|
18
|
|
|
|
|
19
|
|
|
@patch('customers_test.besepa.Api.post', autospec=True) |
|
20
|
|
|
def test_create_bank_account(self, mock): |
|
21
|
|
|
customer = besepa.Customer({'id': '1'}) |
|
22
|
|
|
response = customer.create_bank_account({'iban': 'NL33ABNA0618708937'}) |
|
23
|
|
|
|
|
24
|
|
|
mock.assert_called_once_with( |
|
25
|
|
|
customer.api, 'api/1/customers/1/bank_accounts', {'iban': 'NL33ABNA0618708937'}, {}) |
|
26
|
|
|
assert response.error is None |
|
27
|
|
|
|
|
28
|
|
|
@patch('customers_test.besepa.Api.get', autospec=True) |
|
29
|
|
|
def test_list_bank_accounts(self, mock): |
|
30
|
|
|
customer = besepa.Customer({'id': '1'}) |
|
31
|
|
|
mock.return_value = [{'id': '1', 'iban': 'NL33ABNA0618708937'}] |
|
32
|
|
|
response = customer.list_bank_accounts() |
|
33
|
|
|
|
|
34
|
|
|
mock.assert_called_once_with(response[0].api, 'api/1/customers/1/bank_accounts') |
|
35
|
|
|
assert len(response) == 1 |
|
36
|
|
|
assert isinstance(response[0], Resource) |
|
37
|
|
|
|