Skip to content

Commit 6f21b44

Browse files
committed
Add reorder() method to Account
1 parent 1811fc5 commit 6f21b44

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
- Add update() method to Account
1010
- Add delete() method to Account
1111
- Add move() method to Account
12+
- Add reorder() method to Account
1213
- Add proper testing for ToshlException
1314
- Improve string representation of ToshlException
15+
- refactoring: each entity is in a separate module

tests/test_account.py

+27
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,30 @@ def test_move_account_successful(self, mock_request):
286286
params=None, url='https://api.toshl.com/accounts/1/move',
287287
json=json_payload)
288288
assert response.json() == ''
289+
290+
@mock.patch('toshl.client.requests.request')
291+
def test_reorder_account_successful(self, mock_request):
292+
accounts_list = ['3', '1', '2']
293+
294+
json_payload = {
295+
'order': accounts_list
296+
}
297+
298+
mock_response = mock.Mock()
299+
mock_response.json.return_value = ''
300+
mock_response.status_code = 204
301+
mock_request.return_value = mock_response
302+
303+
client = ToshlClient('abcd1234')
304+
account = Account(client)
305+
response = account.reorder(accounts_list)
306+
307+
mock_request.assert_called_once_with(
308+
headers={
309+
'Authorization': 'Bearer abcd1234',
310+
'Content-Type': 'application/json'
311+
},
312+
method='POST',
313+
params=None, url='https://api.toshl.com/accounts/reorder',
314+
json=json_payload)
315+
assert response.json() == ''

toshl/account.py

+8
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@ def move(self, account_id, position):
5050

5151
return self.client._make_request(
5252
'/accounts/{0}/move'.format(account_id), 'POST', json=json_payload)
53+
54+
def reorder(self, accounts_list):
55+
json_payload = {
56+
'order': accounts_list
57+
}
58+
59+
return self.client._make_request(
60+
'/accounts/reorder', 'POST', json=json_payload)

0 commit comments

Comments
 (0)