diff --git a/boxsdk/object/base_object.py b/boxsdk/object/base_object.py index 81aff447..6cd51bb4 100644 --- a/boxsdk/object/base_object.py +++ b/boxsdk/object/base_object.py @@ -91,7 +91,7 @@ def update_info( The updated information about this object. Must be JSON serializable. Update the object attributes in data.keys(). The semantics of the - values depends on the the type and attributes of the object being + values depends on the type and attributes of the object being updated. For details on particular semantics, refer to the Box developer API documentation . :param params: diff --git a/boxsdk/object/collaboration.py b/boxsdk/object/collaboration.py index 5101e146..6588e666 100644 --- a/boxsdk/object/collaboration.py +++ b/boxsdk/object/collaboration.py @@ -34,12 +34,14 @@ class Collaboration(BaseObject): def update_info( self, *, + data: dict = None, role: Optional[CollaborationRole] = None, status: Optional[CollaborationStatus] = None, **kwargs: Any ) -> 'BaseObject': """Edit an existing collaboration on Box - + :param data: + The updated information about this object. :param role: The new role for this collaboration or None to leave unchanged :param status: @@ -51,12 +53,13 @@ def update_info( :class:`BoxAPIException` if current user doesn't have permissions to edit the collaboration. """ # pylint:disable=arguments-differ - data = {} + if data is None: + data = {} if role: data['role'] = role if status: data['status'] = status - if role == CollaborationRole.OWNER: + if data.get('role', None) == CollaborationRole.OWNER: return super().update_info(data=data, expect_json_response=False, **kwargs) return super().update_info(data=data, **kwargs) diff --git a/docs/usage/collaboration.md b/docs/usage/collaboration.md index 41dc7c5e..8daba93c 100644 --- a/docs/usage/collaboration.md +++ b/docs/usage/collaboration.md @@ -74,15 +74,16 @@ print(f'{collaborator.name} {has_accepted} accepted the collaboration to folder Edit a Collaboration -------------------- -A collaboration can be edited by calling [`collaboration.update_info(*, role=None, status=None, **kwargs)`][update_info]. This method -returns an updated [`Collaboration`][collaboration_class] object, leaving the original unmodified. +A collaboration can be edited by calling [`collaboration.update_info(*, data=None, role=None, status=None, **kwargs)`][update_info]. +This method returns an updated [`Collaboration`][collaboration_class] object, leaving the original unmodified. ```python -from boxsdk.object.collaboration import CollaborationRole, CollaborationStatus +from boxsdk.object.collaboration import CollaborationRole +collaboration_update = {'role': 'owner', 'can_view_path': False} collaboration = client.collaboration(collab_id='12345') -updated_collaboration = collaboration.update_info(role=CollaborationRole.EDITOR) +updated_collaboration = collaboration.update_info(data=collaboration_update) ``` [update_info]: https://box-python-sdk.readthedocs.io/en/latest/boxsdk.object.html#boxsdk.object.collaboration.Collaboration.update_info diff --git a/test/integration_new/object/collaboration_itest.py b/test/integration_new/object/collaboration_itest.py new file mode 100644 index 00000000..3a927fcc --- /dev/null +++ b/test/integration_new/object/collaboration_itest.py @@ -0,0 +1,35 @@ +from datetime import datetime + +import pytest + +from boxsdk.object.collaboration import CollaborationRole + +from test.integration_new.context_managers.box_test_file import BoxTestFile +from test.integration_new.context_managers.box_test_folder import BoxTestFolder + +FILE_TESTS_DIRECTORY_NAME = 'collaboration-integration-tests' + + +@pytest.fixture(scope="module", autouse=True) +def parent_folder(): + with BoxTestFolder(name=f'{FILE_TESTS_DIRECTORY_NAME} {datetime.now()}') as folder: + yield folder + + +def test_collaboration(parent_folder, small_file_path, other_user,): + with BoxTestFile(parent_folder=parent_folder, file_path=small_file_path) as test_file: + collaboration = test_file.collaborate(other_user, CollaborationRole.VIEWER) + try: + assert collaboration.item.id == test_file.id + assert collaboration.accessible_by.id == other_user.id + assert collaboration.role == CollaborationRole.VIEWER + + updated_expiration_date = '2088-01-01T00:00:00-08:00' + collaboration_update = {'role': CollaborationRole.EDITOR, 'expires_at': updated_expiration_date} + updated_collaboration = collaboration.update_info(data=collaboration_update) + + assert updated_collaboration.role == CollaborationRole.EDITOR + assert updated_collaboration.expires_at != collaboration.expires_at + assert updated_collaboration.expires_at == updated_expiration_date + finally: + collaboration.delete() diff --git a/test/unit/object/test_collaboration.py b/test/unit/object/test_collaboration.py index 3ad5a974..c461a86e 100644 --- a/test/unit/object/test_collaboration.py +++ b/test/unit/object/test_collaboration.py @@ -32,6 +32,32 @@ def test_update_info_returns_the_correct_response( assert update_response.object_id == test_collaboration.object_id +@pytest.mark.parametrize('data', [ + {}, + {'role': CollaborationRole.EDITOR, 'status': CollaborationStatus.REJECTED}, + {'role': CollaborationRole.EDITOR, 'status': CollaborationStatus.ACCEPTED}, + {'role': CollaborationRole.EDITOR, 'expires_at': '2025-08-29T23:59:00-07:00'}, + {'role': CollaborationRole.EDITOR, 'can_view_path': True}, +]) +def test_update_info_returns_the_correct_response_with_data_param( + test_collaboration, + mock_box_session, + mock_collab_response, + data): + # pylint:disable=protected-access + expected_url = test_collaboration.get_url() + mock_box_session.put.return_value = mock_collab_response + update_response = test_collaboration.update_info(data=data) + mock_box_session.put.assert_called_once_with( + expected_url, + data=json.dumps(data), + headers=None, + params=None, + ) + assert isinstance(update_response, test_collaboration.__class__) + assert update_response.object_id == test_collaboration.object_id + + def test_update_info_returns_204( test_collaboration, mock_box_session): @@ -39,7 +65,7 @@ def test_update_info_returns_204( data = {'role': CollaborationRole.OWNER, 'status': CollaborationStatus.ACCEPTED} expected_url = test_collaboration.get_url() mock_box_session.put.return_value.ok = True - is_success = test_collaboration.update_info(**data) + is_success = test_collaboration.update_info(data=data) mock_box_session.put.assert_called_once_with( expected_url, data=json.dumps(data),