How to use the boxsdk.object.file.File 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 / unit / object / test_upload_session.py View on Github external
'Content-Type': 'application/json',
        'Digest': 'SHA={}'.format(base64.b64encode(sha1.digest()).decode('utf-8')),
        'If-Match': '7',
    }
    mock_box_session.post.return_value.json.return_value = {
        'entries': [
            {
                'type': file_type,
                'id': file_id,
                'description': 'This is a test description.',
            },
        ],
    }
    created_file = test_upload_session.commit(content_sha1=sha1.digest(), parts=parts, file_attributes=file_attributes, etag=file_etag)
    mock_box_session.post.assert_called_once_with(expected_url, data=json.dumps(expected_data), headers=expected_headers)
    assert isinstance(created_file, File)
    assert created_file.id == file_id
    assert created_file.type == file_type
    assert created_file.description == 'This is a test description.'
github box / box-python-sdk / test / unit / object / test_upload_session.py View on Github external
'offset': 0,
        'total_count': 1,
        'limit': 1000,
    }
    mock_box_session.post.return_value.json.return_value = {
        'entries': [
            {
                'type': file_type,
                'id': file_id,
            },
        ],
    }
    created_file = test_upload_session.commit(content_sha1=sha1.digest())
    mock_box_session.get.assert_called_once_with(expected_get_url, params={'offset': None})
    mock_box_session.post.assert_called_once_with(expected_url, data=json.dumps(expected_data), headers=expected_headers)
    assert isinstance(created_file, File)
    assert created_file.id == file_id
    assert created_file.type == file_type
github box / box-python-sdk / test / unit / util / test_translator.py View on Github external
'name': 'Test File',
                'modified_by': {
                    'type': 'user',
                    'id': '33333',
                    'name': 'Test User',
                },
            },
        ],
    }

    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
github box / box-python-sdk / test / unit / client / test_client.py View on Github external
def mock_file(mock_box_session):
    test_file = File(mock_box_session, '11111')
    return test_file
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 / unit / object / test_folder.py View on Github external
def mock_items(mock_box_session, mock_object_id):
    return [
        {'type': 'file', 'id': mock_object_id},
        {'type': 'folder', 'id': mock_object_id},
        {'type': 'file', 'id': mock_object_id},
    ], [
        File(mock_box_session, mock_object_id),
        Folder(mock_box_session, mock_object_id),
        File(mock_box_session, mock_object_id),
    ]
github box / box-python-sdk / test / unit / object / test_file.py View on Github external
def test_update_contents_does_preflight_check_if_specified(
        test_file,
        mock_file_path,
        preflight_check,
        file_size,
        preflight_fails,
        mock_box_session,
):
    with patch.object(File, 'preflight_check', return_value=None):
        kwargs = {'file_path': mock_file_path}
        if preflight_check:
            kwargs['preflight_check'] = preflight_check
            kwargs['preflight_expected_size'] = file_size
        if preflight_fails:
            test_file.preflight_check.side_effect = BoxAPIException(400)
            with pytest.raises(BoxAPIException):
                test_file.update_contents(**kwargs)
        else:
            test_file.update_contents(**kwargs)

        if preflight_check:
            assert test_file.preflight_check.called_once_with(size=file_size)
            if preflight_fails:
                assert not mock_box_session.post.called
            else:
github box / box-python-sdk / test / unit / object / test_chunked_upload.py View on Github external
flaky_stream.read.side_effect = [b'ab', None, b'c', b'd', b'ef', b'g', b'']

    chunked_uploader = ChunkedUploader(test_upload_session, flaky_stream, file_size)
    uploaded_file = chunked_uploader.start()
    calls = [call(expected_put_url, data=b'ab', headers=expected_headers_first_upload),
             call(expected_put_url, data=b'cd', headers=expected_headers_second_upload),
             call(expected_put_url, data=b'ef', headers=expected_headers_third_upload),
             call(expected_put_url, data=b'g', headers=expected_headers_fourth_upload), ]
    flaky_stream.read.assert_has_calls([call(2), call(2), call(2), call(1), call(2), call(2), call(1)], any_order=False)
    mock_box_session.put.assert_has_calls(calls, any_order=False)
    mock_box_session.post.assert_called_once_with(expected_post_url, data=json.dumps(expected_data),
                                                  headers=expected_headers)
    assert uploaded_file.type == 'file'
    assert uploaded_file.id == '12345'
    assert uploaded_file.description == 'This is a test description'
    assert isinstance(uploaded_file, File)
    assert uploaded_file._session == mock_box_session  # pylint:disable=protected-access
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 / pagination / test_page.py View on Github external
"etag": "1",
        "name": "Stephen Curry Three Pointers"
    }
    entry_2 = {
        "type": "file",
        "id": "818853862",
        "sequence_id": "0",
        "etag": "0",
        "name": "Warriors.jpg"
    }
    response_entries = [entry_1, entry_2]
    response = {"entries": response_entries}
    page = page_builder(response)

    item_checker(Folder, entry_1, page[0])
    item_checker(File, entry_2, page[1])
    assert page[1] == page[-1]