Skip to content

Commit db7375a

Browse files
committed
Add merge() method to Account
1 parent 6f21b44 commit db7375a

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Add delete() method to Account
1111
- Add move() method to Account
1212
- Add reorder() method to Account
13+
- Add merge() method to Account
1314
- Add proper testing for ToshlException
1415
- Improve string representation of ToshlException
1516
- refactoring: each entity is in a separate module

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name='toshl',
55
version='0.0.4',
66
url='https://github.com/andreagrandi/toshl-python',
7-
download_url='https://github.com/andreagrandi/toshl-python/tarball/0.0.3',
7+
download_url='https://github.com/andreagrandi/toshl-python/tarball/0.0.4',
88
author='Andrea Grandi',
99
author_email='[email protected]',
1010
description='Python client library for Toshl API.',

tests/test_account.py

+29
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,32 @@ def test_reorder_account_successful(self, mock_request):
313313
params=None, url='https://api.toshl.com/accounts/reorder',
314314
json=json_payload)
315315
assert response.json() == ''
316+
317+
@mock.patch('toshl.client.requests.request')
318+
def test_merge_account_successful(self, mock_request):
319+
accounts_list = ['1', '2']
320+
dest_account = '2'
321+
322+
json_payload = {
323+
'accounts': accounts_list,
324+
'account': dest_account
325+
}
326+
327+
mock_response = mock.Mock()
328+
mock_response.json.return_value = ''
329+
mock_response.status_code = 204
330+
mock_request.return_value = mock_response
331+
332+
client = ToshlClient('abcd1234')
333+
account = Account(client)
334+
response = account.merge(accounts_list, dest_account)
335+
336+
mock_request.assert_called_once_with(
337+
headers={
338+
'Authorization': 'Bearer abcd1234',
339+
'Content-Type': 'application/json'
340+
},
341+
method='POST',
342+
params=None, url='https://api.toshl.com/accounts/merge',
343+
json=json_payload)
344+
assert response.json() == ''

toshl/account.py

+9
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,12 @@ def reorder(self, accounts_list):
5858

5959
return self.client._make_request(
6060
'/accounts/reorder', 'POST', json=json_payload)
61+
62+
def merge(self, accounts_list, dest_account):
63+
json_payload = {
64+
'accounts': accounts_list,
65+
'account': dest_account
66+
}
67+
68+
return self.client._make_request(
69+
'/accounts/merge', 'POST', json=json_payload)

0 commit comments

Comments
 (0)