How to use the boxsdk.object.user.User function in boxsdk

To help you get started, we’ve selected a few boxsdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github box / box-python-sdk / test / integration / test_as_user.py View on Github external
def test_metadata_endpoint_as_user_causes_as_user_header_to_be_added(
        box_client,
        mock_box_network,
        generic_successful_response,
        mock_user_id,
        as_user_headers,
):
    # pylint:disable=redefined-outer-name
    mock_box_network.session.request.side_effect = [
        generic_successful_response,
    ]
    box_client.file('0').metadata().as_user(User(None, mock_user_id)).get()
    assert mock_box_network.session.request.mock_calls == [
        call(
            'GET',
            '{0}/files/0/metadata/global/properties'.format(API.BASE_API_URL),
            headers=as_user_headers,
        ),
github box / box-python-sdk / test / unit / object / test_base_object.py View on Github external
def objects_for_comparison(test_file, test_folder, mock_user, request, mock_box_session):
    cases = {
        'identical_object': (test_file, test_file, True),
        'same_file': (test_file, File(mock_box_session, test_file.object_id), True),
        'same_folder': (test_folder, Folder(mock_box_session, test_folder.object_id), True),
        'same_user': (mock_user, User(mock_box_session, mock_user.object_id), True),
        'against_none': (test_file, None, False),
        'different_ids': (File(mock_box_session, '1'), File(mock_box_session, '2'), False),
        'different_types': (File(mock_box_session, '1'), Folder(mock_box_session, '1'), False),
        'not_api_object': (test_file, {'id': test_file.object_id, 'type': 'file'}, False),
    }
    return cases[request.param]
github box / box-python-sdk / test / integration / test_as_user.py View on Github external
def test_folder_object_as_user_causes_as_user_header_to_be_added(
        box_client,
        mock_box_network,
        generic_successful_response,
        mock_user_id,
        as_user_headers,
):
    # pylint:disable=redefined-outer-name
    mock_box_network.session.request.side_effect = [
        generic_successful_response,
    ]
    box_client.folder('0').as_user(User(None, mock_user_id)).get()
    assert mock_box_network.session.request.mock_calls == [
        call(
            'GET',
            '{0}/folders/0'.format(API.BASE_API_URL),
            headers=as_user_headers,
            params=None,
        ),
github box / box-python-sdk / test / unit / util / test_translator.py View on Github external
def translator_response(
        bookmark_response,
        box_note_response,
        mock_file_response,
        mock_folder_response,
        mock_group_response,
        mock_user_response,
        mock_web_link_response,
):
    # pylint:disable=redefined-outer-name
    _response_to_class_mapping['bookmark'] = (bookmark_response, BaseObject)
    _response_to_class_mapping['box_note'] = (box_note_response, BaseObject)
    _response_to_class_mapping['file'] = (mock_file_response, File)
    _response_to_class_mapping['folder'] = (mock_folder_response, Folder)
    _response_to_class_mapping['group'] = (mock_group_response, Group)
    _response_to_class_mapping['user'] = (mock_user_response, User)
    _response_to_class_mapping['web_link'] = (mock_web_link_response, WebLink)
github box / box-python-sdk / test / unit / client / test_client.py View on Github external
expected_url = '{0}/users'.format(API.BASE_API_URL)
    mock_box_session.get.return_value.json.return_value = {
        'limit': 100,
        'offset': 0,
        'total_count': 1,
        'entries': [
            {
                'type': 'user',
                'id': '12345',
            }
        ]
    }
    users = mock_client.users()
    user = users.next()
    mock_box_session.get.assert_called_once_with(expected_url, params={'offset': 0})
    assert isinstance(user, User)
    assert user.type == 'user'
    assert user.id == '12345'
github box / box-python-sdk / test / unit / util / test_translator.py View on Github external
}

    results = default_translator.translate(mock_box_session, response_object=response_object)
    test_folder = results['entries'][0]
    test_file = results['entries'][1]

    assert isinstance(test_folder, Folder)
    assert isinstance(test_file, File)
    assert test_folder.object_id == '11111'
    assert test_folder.name == 'Test Folder'
    assert test_file.object_id == '22222'
    assert test_file.name == 'Test File'

    user_1 = test_folder.created_by
    user_2 = test_file.modified_by
    assert isinstance(user_1, User)
    assert isinstance(user_2, User)
    assert user_1 == user_2

    assert test_folder._session == mock_box_session  # pylint:disable=protected-access
    assert test_file._session == mock_box_session  # pylint:disable=protected-access
    assert user_1._session == mock_box_session  # pylint:disable=protected-access
    assert user_2._session == mock_box_session  # pylint:disable=protected-access

    # It should not modify the original
    assert isinstance(response_object['entries'][0], dict)
    assert isinstance(response_object['entries'][1], dict)
github box / box-python-sdk / test / unit / object / test_group_membership.py View on Github external
else:
        user_id, group_id = None, None

    group_membership = GroupMembership(mock_box_session, fake_id, response_object, **kwargs)

    assert group_membership.object_id == fake_id

    # pylint:disable=protected-access
    assert group_membership._session == mock_box_session
    if response_object:
        assert group_membership._response_object is response_object
    else:
        assert not group_membership._response_object
    # pylint:enable=protected-access

    _assert_object_is_valid(group_membership.user, bool(response_object), user_id, User, kwargs.get('user'))
    _assert_object_is_valid(group_membership.group, bool(response_object), group_id, Group, kwargs.get('group'))
github box / box-python-sdk / test / unit / client / test_client.py View on Github external
def mock_user(mock_box_session):
    user = User(mock_box_session, '12345')
    return user
github box / box-python-sdk / test / integration / test_as_user.py View on Github external
def test_group_membership_object_as_user_causes_as_user_header_to_be_added(
        box_client,
        mock_box_network,
        generic_successful_response,
        mock_user_id,
        as_user_headers,
):
    # pylint:disable=redefined-outer-name
    mock_box_network.session.request.side_effect = [
        generic_successful_response,
    ]
    box_client.group_membership('0').as_user(User(None, mock_user_id)).get()
    assert mock_box_network.session.request.mock_calls == [
        call(
            'GET',
            '{0}/group_memberships/0'.format(API.BASE_API_URL),
            headers=as_user_headers,
            params=None,
        ),
github box / box-python-sdk / boxsdk / object / folder.py View on Github external
def __init__(self, collaborator):
        if isinstance(collaborator, User):
            self._setup(user=collaborator)
        elif isinstance(collaborator, Group):
            self._setup(group=collaborator)
        elif isinstance(collaborator, text_type):
            self._setup(email_address=collaborator)
        else:
            raise TypeError('Collaborator must be User, Group, or unicode string')