diff --git a/boxsdk/object/base_item.py b/boxsdk/object/base_item.py index f56bde00..05592066 100644 --- a/boxsdk/object/base_item.py +++ b/boxsdk/object/base_item.py @@ -87,12 +87,15 @@ def create_shared_link(self, **kwargs: Any) -> Any: if kwargs.get('unshared_at') is not SDK_VALUE_NOT_SET: shared_link['unshared_at'] = normalize_date_to_rfc3339_format(kwargs.get('unshared_at')) - if kwargs.get('allow_download') is not None or kwargs.get('allow_preview') is not None: - shared_link['permissions'] = {} - if kwargs.get('allow_download') is not None: - shared_link['permissions']['can_download'] = kwargs.get('allow_download') - if kwargs.get('allow_preview') is not None: - shared_link['permissions']['can_preview'] = kwargs.get('allow_preview') + permissions = {} + if kwargs.get('allow_download') is not None: + permissions['can_download'] = kwargs.get('allow_download') + if kwargs.get('allow_preview') is not None: + permissions['can_preview'] = kwargs.get('allow_preview') + if kwargs.get('allow_edit') is not None: + permissions['can_edit'] = kwargs.get('allow_edit') + if permissions: + shared_link['permissions'] = permissions if kwargs.get('password') is not None: shared_link['password'] = kwargs.get('password') diff --git a/boxsdk/object/file.py b/boxsdk/object/file.py index 7e9c15ae..53fd17e5 100644 --- a/boxsdk/object/file.py +++ b/boxsdk/object/file.py @@ -1,7 +1,7 @@ import json import os from datetime import datetime -from typing import TYPE_CHECKING, Optional, Tuple, Union, IO, Iterable, List +from typing import TYPE_CHECKING, Optional, Tuple, Union, IO, Iterable, List, Any from boxsdk.util.datetime_formatter import normalize_date_to_rfc3339_format from .item import Item @@ -367,6 +367,127 @@ def unlock(self) -> 'File': data = {'lock': None} return self.update_info(data=data) + @api_call + def create_shared_link( + self, + *, + access: Optional[str] = None, + etag: Optional[str] = None, + unshared_at: Union[datetime, str, None] = SDK_VALUE_NOT_SET, + allow_download: Optional[bool] = None, + allow_preview: Optional[bool] = None, + allow_edit: Optional[bool] = None, + password: Optional[str] = None, + vanity_name: Optional[str] = None, + **kwargs: Any + ) -> 'File': + """ + Baseclass override. + + :param access: + Determines who can access the shared link. May be open, company, or collaborators. If no access is + specified, the default access will be used. + :param etag: + If specified, instruct the Box API to create the link only if the current version's etag matches. + :param unshared_at: + The date on which this link should be disabled. May only be set if the current user is not a free user + and has permission to set expiration dates. Takes a datetime string supported by the dateutil library + or a datetime.datetime object. If no timezone info provided, local timezone will be applied. + The time portion can be omitted, which defaults to midnight (00:00:00) on that date. + :param allow_download: + Whether the file being shared can be downloaded when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param allow_preview: + Whether the file being shared can be previewed when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param allow_edit: + Whether the file being shared can be edited when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param password: + The password required to view this link. If no password is specified then no password will be set. + Please notice that this is a premium feature, which might not be available to your app. + :param vanity_name: + Defines a custom vanity name to use in the shared link URL, eg. https://app.box.com/v/my-custom-vanity-name. + If this parameter is None, the standard shared link URL will be used. + :param kwargs: + Used to fulfill the contract of overriden method + :return: + The updated object with shared link. + Returns a new object of the same type, without modifying the original object passed as self. + :raises: :class:`BoxAPIException` if the specified etag doesn't match the latest version of the file. + """ + # pylint:disable=arguments-differ + return super().create_shared_link( + access=access, + etag=etag, + unshared_at=unshared_at, + allow_download=allow_download, + allow_preview=allow_preview, + allow_edit=allow_edit, + password=password, + vanity_name=vanity_name + ) + + @api_call + def get_shared_link( + self, + *, + access: Optional[str] = None, + etag: Optional[str] = None, + unshared_at: Union[datetime, str, None] = SDK_VALUE_NOT_SET, + allow_download: Optional[bool] = None, + allow_preview: Optional[bool] = None, + allow_edit: Optional[bool] = None, + password: Optional[str] = None, + vanity_name: Optional[str] = None, + **kwargs: Any + ) -> 'str': + """ + Baseclass override. + + :param access: + Determines who can access the shared link. May be open, company, or collaborators. If no access is + specified, the default access will be used. + :param etag: + If specified, instruct the Box API to create the link only if the current version's etag matches. + :param unshared_at: + The date on which this link should be disabled. May only be set if the current user is not a free user + and has permission to set expiration dates. Takes a datetime string supported by the dateutil library + or a datetime.datetime object. If no timezone info provided, local timezone will be applied. + The time portion can be omitted, which defaults to midnight (00:00:00) on that date. + :param allow_download: + Whether the file being shared can be downloaded when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param allow_preview: + Whether the file being shared can be previewed when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param allow_edit: + Whether the file being shared can be edited when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param password: + The password required to view this link. If no password is specified then no password will be set. + Please notice that this is a premium feature, which might not be available to your app. + :param vanity_name: + Defines a custom vanity name to use in the shared link URL, eg. https://app.box.com/v/my-custom-vanity-name. + If this parameter is None, the standard shared link URL will be used. + :param kwargs: + Used to fulfill the contract of overriden method + :returns: + The URL of the shared link. + :raises: :class:`BoxAPIException` if the specified etag doesn't match the latest version of the file. + """ + # pylint:disable=arguments-differ + return super().get_shared_link( + access=access, + etag=etag, + unshared_at=unshared_at, + allow_download=allow_download, + allow_preview=allow_preview, + allow_edit=allow_edit, + password=password, + vanity_name=vanity_name + ) + @api_call def get_shared_link_download_url( self, diff --git a/boxsdk/object/folder.py b/boxsdk/object/folder.py index ff5593f2..fd0f9e61 100644 --- a/boxsdk/object/folder.py +++ b/boxsdk/object/folder.py @@ -10,6 +10,7 @@ from boxsdk.pagination.marker_based_object_collection import MarkerBasedObjectCollection from boxsdk.util.api_call_decorator import api_call from boxsdk.util.datetime_formatter import normalize_date_to_rfc3339_format +from boxsdk.util.default_arg_value import SDK_VALUE_NOT_SET from boxsdk.util.text_enum import TextEnum if TYPE_CHECKING: @@ -426,6 +427,117 @@ def update_sync_state(self, sync_state: FolderSyncState) -> 'Folder': } return self.update_info(data=data) + @api_call + def create_shared_link( + self, + *, + access: Optional[str] = None, + etag: Optional[str] = None, + unshared_at: Union[datetime, str, None] = SDK_VALUE_NOT_SET, + allow_download: Optional[bool] = None, + allow_preview: Optional[bool] = None, + password: Optional[str] = None, + vanity_name: Optional[str] = None, + **kwargs: Any + ) -> 'Folder': + """ + Baseclass override. + + :param access: + Determines who can access the shared link. May be open, company, or collaborators. If no access is + specified, the default access will be used. + :param etag: + If specified, instruct the Box API to create the link only if the current version's etag matches. + :param unshared_at: + The date on which this link should be disabled. May only be set if the current user is not a free user + and has permission to set expiration dates. Takes a datetime string supported by the dateutil library + or a datetime.datetime object. If no timezone info provided, local timezone will be applied. + The time portion can be omitted, which defaults to midnight (00:00:00) on that date. + :param allow_download: + Whether the folder being shared can be downloaded when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param allow_preview: + Whether the folder being shared can be previewed when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param password: + The password required to view this link. If no password is specified then no password will be set. + Please notice that this is a premium feature, which might not be available to your app. + :param vanity_name: + Defines a custom vanity name to use in the shared link URL, eg. https://app.box.com/v/my-custom-vanity-name. + If this parameter is None, the standard shared link URL will be used. + :param kwargs: + Used to fulfill the contract of overriden method + :return: + The updated object with shared link. + Returns a new object of the same type, without modifying the original object passed as self. + :raises: :class:`BoxAPIException` if the specified etag doesn't match the latest version of the folder. + """ + # pylint:disable=arguments-differ + return super().create_shared_link( + access=access, + etag=etag, + unshared_at=unshared_at, + allow_download=allow_download, + allow_preview=allow_preview, + password=password, + vanity_name=vanity_name + ) + + @api_call + def get_shared_link( + self, + *, + access: Optional[str] = None, + etag: Optional[str] = None, + unshared_at: Union[datetime, str, None] = SDK_VALUE_NOT_SET, + allow_download: Optional[bool] = None, + allow_preview: Optional[bool] = None, + password: Optional[str] = None, + vanity_name: Optional[str] = None, + **kwargs: Any + ) -> 'str': + """ + Baseclass override. + + :param access: + Determines who can access the shared link. May be open, company, or collaborators. If no access is + specified, the default access will be used. + :param etag: + If specified, instruct the Box API to create the link only if the current version's etag matches. + :param unshared_at: + The date on which this link should be disabled. May only be set if the current user is not a free user + and has permission to set expiration dates. Takes a datetime string supported by the dateutil library + or a datetime.datetime object. If no timezone info provided, local timezone will be applied. + The time portion can be omitted, which defaults to midnight (00:00:00) on that date. + :param allow_download: + Whether the folder being shared can be downloaded when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param allow_preview: + Whether the folder being shared can be previewed when accessed via the shared link. + If this parameter is None, the default setting will be used. + :param password: + The password required to view this link. If no password is specified then no password will be set. + Please notice that this is a premium feature, which might not be available to your app. + :param vanity_name: + Defines a custom vanity name to use in the shared link URL, eg. https://app.box.com/v/my-custom-vanity-name. + If this parameter is None, the standard shared link URL will be used. + :param kwargs: + Used to fulfill the contract of overriden method + :returns: + The URL of the shared link. + :raises: :class:`BoxAPIException` if the specified etag doesn't match the latest version of the folder. + """ + # pylint:disable=arguments-differ + return super().get_shared_link( + access=access, + etag=etag, + unshared_at=unshared_at, + allow_download=allow_download, + allow_preview=allow_preview, + password=password, + vanity_name=vanity_name + ) + @api_call def add_collaborator( self, @@ -437,7 +549,7 @@ def add_collaborator( """Add a collaborator to the folder :param collaborator: - collaborator to add. May be a User, Group, or email address (unicode string) + collaborator to add. It may be a User, Group, or email address (unicode string) :param role: The collaboration role :param notify: diff --git a/boxsdk/object/item.py b/boxsdk/object/item.py index f30f2ddb..e79aad1c 100644 --- a/boxsdk/object/item.py +++ b/boxsdk/object/item.py @@ -1,5 +1,4 @@ import json -from datetime import datetime from typing import TYPE_CHECKING, Optional, Iterable, Any, Union from boxsdk.util.text_enum import TextEnum @@ -7,7 +6,6 @@ from ..exception import BoxAPIException from .metadata import Metadata from ..util.api_call_decorator import api_call -from ..util.default_arg_value import SDK_VALUE_NOT_SET from ..pagination.marker_based_dict_collection import MarkerBasedDictCollection from ..pagination.marker_based_object_collection import MarkerBasedObjectCollection @@ -139,117 +137,6 @@ def get(self, *, fields: Iterable[str] = None, etag: Optional[str] = None, **kwa headers = {'If-None-Match': etag} if etag is not None else None return super().get(fields=fields, headers=headers, **kwargs) - @api_call - def create_shared_link( - self, - *, - access: Optional[str] = None, - etag: Optional[str] = None, - unshared_at: Union[datetime, str, None] = SDK_VALUE_NOT_SET, - allow_download: Optional[bool] = None, - allow_preview: Optional[bool] = None, - password: Optional[str] = None, - vanity_name: Optional[str] = None, - **kwargs: Any - ) -> 'Item': - """ - Baseclass override. - - :param access: - Determines who can access the shared link. May be open, company, or collaborators. If no access is - specified, the default access will be used. - :param etag: - If specified, instruct the Box API to create the link only if the current version's etag matches. - :param unshared_at: - The date on which this link should be disabled. May only be set if the current user is not a free user - and has permission to set expiration dates. Takes a datetime string supported by the dateutil library - or a datetime.datetime object. If no timezone info provided, local timezone will be applied. - The time portion can be omitted, which defaults to midnight (00:00:00) on that date. - :param allow_download: - Whether or not the item being shared can be downloaded when accessed via the shared link. - If this parameter is None, the default setting will be used. - :param allow_preview: - Whether or not the item being shared can be previewed when accessed via the shared link. - If this parameter is None, the default setting will be used. - :param password: - The password required to view this link. If no password is specified then no password will be set. - Please notice that this is a premium feature, which might not be available to your app. - :param vanity_name: - Defines a custom vanity name to use in the shared link URL, eg. https://app.box.com/v/my-custom-vanity-name. - If this parameter is None, the standard shared link URL will be used. - :param kwargs: - Used to fulfill the contract of overriden method - :return: - The updated object with shared link. - Returns a new object of the same type, without modifying the original object passed as self. - :raises: :class:`BoxAPIException` if the specified etag doesn't match the latest version of the item. - """ - # pylint:disable=arguments-differ - return super().create_shared_link( - access=access, - etag=etag, - unshared_at=unshared_at, - allow_download=allow_download, - allow_preview=allow_preview, - password=password, - vanity_name=vanity_name - ) - - @api_call - def get_shared_link( - self, - *, - access: Optional[str] = None, - etag: Optional[str] = None, - unshared_at: Union[datetime, str, None] = SDK_VALUE_NOT_SET, - allow_download: Optional[bool] = None, - allow_preview: Optional[bool] = None, - password: Optional[str] = None, - vanity_name: Optional[str] = None, - **kwargs: Any - ) -> 'str': - """ - Baseclass override. - - :param access: - Determines who can access the shared link. May be open, company, or collaborators. If no access is - specified, the default access will be used. - :param etag: - If specified, instruct the Box API to create the link only if the current version's etag matches. - :param unshared_at: - The date on which this link should be disabled. May only be set if the current user is not a free user - and has permission to set expiration dates. Takes a datetime string supported by the dateutil library - or a datetime.datetime object. If no timezone info provided, local timezone will be applied. - The time portion can be omitted, which defaults to midnight (00:00:00) on that date. - :param allow_download: - Whether or not the item being shared can be downloaded when accessed via the shared link. - If this parameter is None, the default setting will be used. - :param allow_preview: - Whether or not the item being shared can be previewed when accessed via the shared link. - If this parameter is None, the default setting will be used. - :param password: - The password required to view this link. If no password is specified then no password will be set. - Please notice that this is a premium feature, which might not be available to your app. - :param vanity_name: - Defines a custom vanity name to use in the shared link URL, eg. https://app.box.com/v/my-custom-vanity-name. - If this parameter is None, the standard shared link URL will be used. - :param kwargs: - Used to fulfill the contract of overriden method - :returns: - The URL of the shared link. - :raises: :class:`BoxAPIException` if the specified etag doesn't match the latest version of the item. - """ - # pylint:disable=arguments-differ - return super().get_shared_link( - access=access, - etag=etag, - unshared_at=unshared_at, - allow_download=allow_download, - allow_preview=allow_preview, - password=password, - vanity_name=vanity_name - ) - @api_call def remove_shared_link(self, *, etag: Optional[str] = None, **kwargs: Any) -> bool: """ diff --git a/test/integration_new/conftest.py b/test/integration_new/conftest.py index 51a7af7a..2e733741 100644 --- a/test/integration_new/conftest.py +++ b/test/integration_new/conftest.py @@ -1,5 +1,6 @@ +from test.integration_new.context_managers.box_test_user import BoxTestUser from test.integration_new.context_managers.local_large_file import LocalLargeFile -from test.integration_new import util +from test.integration_new import util, CLIENT import pytest @@ -42,3 +43,14 @@ def large_file_name(): def large_file(large_file_name): with LocalLargeFile(name=large_file_name) as large_file: yield large_file + + +@pytest.fixture(scope="package") +def other_user(): + with BoxTestUser(login=None) as other_user: + yield other_user + + +@pytest.fixture(scope="package") +def other_client(other_user): + yield CLIENT.as_user(other_user) diff --git a/test/integration_new/object/file_itest.py b/test/integration_new/object/file_itest.py index 61fe1d0f..cdd727d5 100644 --- a/test/integration_new/object/file_itest.py +++ b/test/integration_new/object/file_itest.py @@ -8,8 +8,7 @@ from boxsdk import BoxAPIException from test.integration_new.context_managers.box_retention_policy import BoxRetentionPolicy -from test.integration_new.context_managers.box_test_user import BoxTestUser -from test.integration_new import util, CLIENT +from test.integration_new import util from test.integration_new.context_managers.box_test_file import BoxTestFile from test.integration_new.context_managers.box_test_folder import BoxTestFolder @@ -29,17 +28,6 @@ def test_file(parent_folder, small_file_path): yield file -@pytest.fixture(scope="module") -def other_user(): - with BoxTestUser(login=None) as other_user: - yield other_user - - -@pytest.fixture(scope="module") -def other_client(other_user): - yield CLIENT.as_user(other_user) - - def test_preflight_check(test_file): file_size = 1213 accelerator_url = test_file.preflight_check(size=file_size, name=util.random_name()) @@ -128,6 +116,17 @@ def test_lock_and_unlock(parent_folder, small_file_path, small_file_v2_path, oth assert file.get(fields=('lock',)).lock is None +def test_get_shared_link(parent_folder, small_file_path, other_user, other_client): + with BoxTestFile(parent_folder=parent_folder, file_path=small_file_path) as file: + file.collaborate(accessible_by=other_user, role='editor') + + shared_link = other_client.file(file.object_id).get_shared_link(allow_edit=True, allow_preview=True, allow_download=True) + + result_permissions = file.get().shared_link['permissions'] + assert result_permissions == {'can_preview': True, 'can_download': True, 'can_edit': True} + assert other_client.get_shared_item(shared_link).id == file.id + + def test_get_shared_link_download_url(parent_folder, small_file_path, other_user, other_client): with BoxTestFile(parent_folder=parent_folder, file_path=small_file_path) as file: file.collaborate(accessible_by=other_user, role='editor') diff --git a/test/integration_new/object/folder_itest.py b/test/integration_new/object/folder_itest.py index 81cf65a3..3a952cd8 100644 --- a/test/integration_new/object/folder_itest.py +++ b/test/integration_new/object/folder_itest.py @@ -128,6 +128,17 @@ def test_create_subfolder(parent_folder): util.permanently_delete(created_subfolder) +def test_get_shared_link(parent_folder, other_user, other_client): + with BoxTestFolder(parent_folder=parent_folder) as folder: + folder.collaborate(accessible_by=other_user, role='editor') + + shared_link = other_client.folder(folder.object_id).get_shared_link(allow_preview=True, allow_download=True) + + result_permissions = folder.get().shared_link['permissions'] + assert result_permissions == {'can_preview': True, 'can_download': True, 'can_edit': False} + assert other_client.get_shared_item(shared_link).id == folder.id + + @pytest.mark.parametrize( 'collaborator', [ lazy_fixture('user'), diff --git a/test/unit/object/conftest.py b/test/unit/object/conftest.py index 8c279290..279391fa 100644 --- a/test/unit/object/conftest.py +++ b/test/unit/object/conftest.py @@ -341,6 +341,11 @@ def shared_link_can_preview(request): return request.param +@pytest.fixture(params=(True, False, None)) +def shared_link_can_edit(request): + return request.param + + @pytest.fixture(params=('open', None)) def shared_link_access(request): return request.param diff --git a/test/unit/object/test_file.py b/test/unit/object/test_file.py index ed37706e..13b56f5d 100644 --- a/test/unit/object/test_file.py +++ b/test/unit/object/test_file.py @@ -586,6 +586,67 @@ def test_preflight_check( assert accelerator_url == mock_accelerator_upload_url_for_update +def test_get_shared_link( + test_file, + mock_box_session, + shared_link_access, + shared_link_unshared_at, + shared_link_password, + shared_link_can_download, + shared_link_can_preview, + shared_link_can_edit, + shared_link_vanity_name, + test_url, + etag, + if_match_header, +): + # pylint:disable=redefined-outer-name, protected-access + expected_url = test_file.get_url() + mock_box_session.put.return_value.json.return_value = { + 'type': test_file.object_type, + 'id': test_file.object_id, + 'shared_link': { + 'url': test_url, + }, + } + expected_data = {'shared_link': {}} + if shared_link_access is not None: + expected_data['shared_link']['access'] = shared_link_access + if shared_link_unshared_at is not SDK_VALUE_NOT_SET: + expected_data['shared_link']['unshared_at'] = normalize_date_to_rfc3339_format(shared_link_unshared_at) + permissions = {} + if shared_link_can_download is not None: + permissions['can_download'] = shared_link_can_download + if shared_link_can_preview is not None: + permissions['can_preview'] = shared_link_can_preview + if shared_link_can_edit is not None: + permissions['can_edit'] = shared_link_can_edit + if permissions: + expected_data['shared_link']['permissions'] = permissions + if shared_link_password is not None: + expected_data['shared_link']['password'] = shared_link_password + if shared_link_vanity_name is not None: + expected_data['shared_link']['vanity_name'] = shared_link_vanity_name + + url = test_file.get_shared_link( + etag=etag, + access=shared_link_access, + unshared_at=shared_link_unshared_at, + password=shared_link_password, + allow_download=shared_link_can_download, + allow_preview=shared_link_can_preview, + allow_edit=shared_link_can_edit, + vanity_name=shared_link_vanity_name, + ) + mock_box_session.put.assert_called_once_with( + expected_url, + data=json.dumps(expected_data), + headers=if_match_header, + params=None, + ) + assert url == test_url + + def test_get_shared_link_download_url( test_file, mock_box_session, diff --git a/test/unit/object/test_folder.py b/test/unit/object/test_folder.py index 5a5c5b68..21b099ed 100644 --- a/test/unit/object/test_folder.py +++ b/test/unit/object/test_folder.py @@ -23,6 +23,7 @@ # pylint:disable=protected-access # pylint:disable=redefined-outer-name from boxsdk.util.datetime_formatter import normalize_date_to_rfc3339_format +from boxsdk.util.default_arg_value import SDK_VALUE_NOT_SET @pytest.fixture() @@ -437,6 +438,62 @@ def test_create_subfolder(test_folder, mock_box_session, mock_object_id, mock_fo assert new_folder.object_id == mock_object_id +def test_get_shared_link( + test_folder, + mock_box_session, + shared_link_access, + shared_link_unshared_at, + shared_link_password, + shared_link_can_download, + shared_link_can_preview, + shared_link_vanity_name, + test_url, + etag, + if_match_header, +): + # pylint:disable=redefined-outer-name, protected-access + expected_url = test_folder.get_url() + mock_box_session.put.return_value.json.return_value = { + 'type': test_folder.object_type, + 'id': test_folder.object_id, + 'shared_link': { + 'url': test_url, + }, + } + expected_data = {'shared_link': {}} + if shared_link_access is not None: + expected_data['shared_link']['access'] = shared_link_access + if shared_link_unshared_at is not SDK_VALUE_NOT_SET: + expected_data['shared_link']['unshared_at'] = normalize_date_to_rfc3339_format(shared_link_unshared_at) + if shared_link_can_download is not None or shared_link_can_preview is not None: + expected_data['shared_link']['permissions'] = permissions = {} + if shared_link_can_download is not None: + permissions['can_download'] = shared_link_can_download + if shared_link_can_preview is not None: + permissions['can_preview'] = shared_link_can_preview + if shared_link_password is not None: + expected_data['shared_link']['password'] = shared_link_password + if shared_link_vanity_name is not None: + expected_data['shared_link']['vanity_name'] = shared_link_vanity_name + + url = test_folder.get_shared_link( + etag=etag, + access=shared_link_access, + unshared_at=shared_link_unshared_at, + password=shared_link_password, + allow_download=shared_link_can_download, + allow_preview=shared_link_can_preview, + vanity_name=shared_link_vanity_name, + ) + mock_box_session.put.assert_called_once_with( + expected_url, + data=json.dumps(expected_data), + headers=if_match_header, + params=None, + ) + assert url == test_url + + @pytest.mark.parametrize('sync_state', iter(FolderSyncState)) def test_update_sync_state(test_folder, mock_folder_response, mock_box_session, sync_state): expected_url = test_folder.get_url() diff --git a/test/unit/object/test_item.py b/test/unit/object/test_item.py index b335f490..a540f739 100644 --- a/test/unit/object/test_item.py +++ b/test/unit/object/test_item.py @@ -5,8 +5,6 @@ from boxsdk.config import API from boxsdk.object.watermark import Watermark from boxsdk.object.collaboration import Collaboration -from boxsdk.util.datetime_formatter import normalize_date_to_rfc3339_format -from boxsdk.util.default_arg_value import SDK_VALUE_NOT_SET from boxsdk.exception import BoxValueError @@ -44,63 +42,6 @@ def test_update_info_with_default_request_kwargs(test_item_and_response, mock_bo assert update_response.object_id == test_item.object_id -def test_get_shared_link( - test_item_and_response, - mock_box_session, - shared_link_access, - shared_link_unshared_at, - shared_link_password, - shared_link_can_download, - shared_link_can_preview, - shared_link_vanity_name, - test_url, - etag, - if_match_header, -): - # pylint:disable=redefined-outer-name, protected-access - test_item, _ = test_item_and_response - expected_url = test_item.get_url() - mock_box_session.put.return_value.json.return_value = { - 'type': test_item.object_type, - 'id': test_item.object_id, - 'shared_link': { - 'url': test_url, - }, - } - expected_data = {'shared_link': {}} - if shared_link_access is not None: - expected_data['shared_link']['access'] = shared_link_access - if shared_link_unshared_at is not SDK_VALUE_NOT_SET: - expected_data['shared_link']['unshared_at'] = normalize_date_to_rfc3339_format(shared_link_unshared_at) - if shared_link_can_download is not None or shared_link_can_preview is not None: - expected_data['shared_link']['permissions'] = permissions = {} - if shared_link_can_download is not None: - permissions['can_download'] = shared_link_can_download - if shared_link_can_preview is not None: - permissions['can_preview'] = shared_link_can_preview - if shared_link_password is not None: - expected_data['shared_link']['password'] = shared_link_password - if shared_link_vanity_name is not None: - expected_data['shared_link']['vanity_name'] = shared_link_vanity_name - - url = test_item.get_shared_link( - etag=etag, - access=shared_link_access, - unshared_at=shared_link_unshared_at, - password=shared_link_password, - allow_download=shared_link_can_download, - allow_preview=shared_link_can_preview, - vanity_name=shared_link_vanity_name, - ) - mock_box_session.put.assert_called_once_with( - expected_url, - data=json.dumps(expected_data), - headers=if_match_header, - params=None, - ) - assert url == test_url - - def test_clear_unshared_at_for_shared_link( test_item_and_response, mock_box_session,