Skip to content

Commit 30e4283

Browse files
Fix bug with updating a collaboration role to owner (#536)
1 parent 84587aa commit 30e4283

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Release History
66
Next Release
77
++++++++
88
- Allow ints to be passed in as item IDs
9+
- Fix bug with updating a collaboration role to owner
910

1011
2.9.0 (2020-06-23)
1112
++++++++

boxsdk/object/base_object.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,16 @@ def update_info(self, data, params=None, headers=None, **kwargs):
123123
:rtype:
124124
:class:`BaseObject`
125125
"""
126+
# pylint:disable=no-else-return
126127
url = self.get_url()
127128
box_response = self._session.put(url, data=json.dumps(data), params=params, headers=headers, **kwargs)
128-
return self.translator.translate(
129-
session=self._session,
130-
response_object=box_response.json(),
131-
)
129+
if 'expect_json_response' in kwargs and not kwargs['expect_json_response']:
130+
return box_response.ok
131+
else:
132+
return self.translator.translate(
133+
session=self._session,
134+
response_object=box_response.json(),
135+
)
132136

133137
@api_call
134138
def delete(self, params=None, headers=None):

boxsdk/object/collaboration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ def update_info(self, role=None, status=None):
5252
:raises:
5353
:class:`BoxAPIException` if current user doesn't have permissions to edit the collaboration.
5454
"""
55-
# pylint:disable=arguments-differ
55+
# pylint:disable=arguments-differ,no-else-return
5656
data = {}
5757
if role:
5858
data['role'] = role
5959
if status:
6060
data['status'] = status
61-
return super(Collaboration, self).update_info(data=data)
61+
if role == CollaborationRole.OWNER:
62+
return super(Collaboration, self).update_info(data=data, expect_json_response=False)
63+
else:
64+
return super(Collaboration, self).update_info(data=data)
6265

6366
@api_call
6467
def accept(self):

test/unit/object/test_collaboration.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ def test_update_info_returns_the_correct_response(
3737
assert update_response.object_id == test_collaboration.object_id
3838

3939

40+
def test_update_info_returns_204(
41+
test_collaboration,
42+
mock_box_session):
43+
# pylint:disable=protected-access
44+
data = {'role': CollaborationRole.OWNER, 'status': CollaborationStatus.ACCEPTED}
45+
expected_url = test_collaboration.get_url()
46+
mock_box_session.put.return_value.ok = True
47+
is_success = test_collaboration.update_info(**data)
48+
mock_box_session.put.assert_called_once_with(
49+
expected_url,
50+
data=json.dumps(data),
51+
expect_json_response=False,
52+
headers=None,
53+
params=None,
54+
)
55+
assert is_success is True
56+
57+
4058
def test_accept_pending_collaboration(test_collaboration, mock_box_session):
4159
# pylint:disable=protected-access
4260
new_status = 'accepted'

0 commit comments

Comments
 (0)