How to use the boxsdk.config.API 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_metadata_template.py View on Github external
def test_delete(test_metadata_template, mock_box_session):
    expected_url = '{0}/metadata_templates/{1}/{2}/schema'.format(
        API.BASE_API_URL,
        test_metadata_template.scope,
        test_metadata_template.template_key,
    )
    mock_box_session.delete.return_value.ok = True

    result = test_metadata_template.delete()

    mock_box_session.delete.assert_called_once_with(expected_url, expect_json_response=False, headers=None, params={})
    assert result is True
github box / box-python-sdk / test / integration / test_with_shared_link.py View on Github external
box_client,
        mock_box_network,
        generic_successful_response,
        shared_link,
        shared_link_password,
        box_api_headers,
):
    # pylint:disable=redefined-outer-name
    mock_box_network.session.request.side_effect = [
        generic_successful_response,
    ]
    box_client.file('0').metadata().with_shared_link(shared_link, shared_link_password).get()
    assert mock_box_network.session.request.mock_calls == [
        call(
            'GET',
            '{0}/files/0/metadata/global/properties'.format(API.BASE_API_URL),
            headers=box_api_headers,
        ),
github box / box-python-sdk / test / unit / object / test_folder.py View on Github external
def test_preflight(
        test_folder,
        mock_object_id,
        mock_box_session,
        mock_accelerator_response_for_new_uploads,
        mock_new_upload_accelerator_url,
):
    new_file_size, new_file_name = 100, 'foo.txt'
    mock_box_session.options.return_value = mock_accelerator_response_for_new_uploads

    accelerator_url = test_folder.preflight_check(size=new_file_size, name=new_file_name)

    mock_box_session.options.assert_called_once_with(
        url='{0}/files/content'.format(API.BASE_API_URL),
        expect_json_response=True,
        data=json.dumps(
            {
                'size': new_file_size,
                'name': new_file_name,
                'parent': {'id': mock_object_id},
            }
        ),
    )
    assert accelerator_url == mock_new_upload_accelerator_url
github box / box-python-sdk / test / unit / object / test_file.py View on Github external
def test_create_upload_session(test_file, mock_box_session):
    expected_url = '{0}/files/{1}/upload_sessions'.format(API.UPLOAD_URL, test_file.object_id)
    file_size = 197520
    part_size = 12345
    total_parts = 16
    num_parts_processed = 0
    upload_session_type = 'upload_session'
    upload_session_id = 'F971964745A5CD0C001BBE4E58196BFD'
    file_name = 'test_file.pdf'
    expected_data = {
        'file_id': test_file.object_id,
        'file_size': file_size,
        'file_name': file_name
    }
    mock_box_session.post.return_value.json.return_value = {
        'id': upload_session_id,
        'type': upload_session_type,
        'num_parts_processed': num_parts_processed,
github box / box-python-sdk / test / unit / object / test_collaboration.py View on Github external
def test_reject_pending_collaboration(test_collaboration, mock_box_session):
    # pylint:disable=protected-access
    new_status = 'rejected'
    expected_url = '{0}/collaborations/{1}'.format(API.BASE_API_URL, test_collaboration.object_id)
    mock_collab_response = {
        'type': 'collaboration',
        'id': '1234',
        'status': 'rejected',
    }
    mock_box_session.put.return_value.json.return_value = mock_collab_response
    response = test_collaboration.reject()
    update_body = {
        'status': 'rejected'
    }
    mock_box_session.put.assert_called_once_with(
        expected_url,
        data=json.dumps(update_body),
        headers=None,
        params=None,
    )
github box / box-python-sdk / test / unit / object / test_user.py View on Github external
def test_user_url(mock_user):
    # pylint:disable=redefined-outer-name, protected-access
    assert mock_user.get_url() == '{0}/{1}/{2}'.format(API.BASE_API_URL, 'users', mock_user.object_id)
github box / box-python-sdk / boxsdk / session / session.py View on Github external
request_headers.update(headers or {})

        request = self.box_request_constructor(
            url=url,
            method=method,
            headers=request_headers,
            auto_session_renewal=auto_session_renewal,
            expect_json_response=expect_json_response,
        )

        network_response = self._send_request(request, **kwargs)

        while True:
            retry = self._get_retry_request_callable(network_response, attempt_number, request, **kwargs)

            if retry is None or attempt_number >= API.MAX_RETRY_ATTEMPTS:
                break

            attempt_number += 1
            self._logger.debug('Retrying request')
            network_response = retry(request, **kwargs)

        self._raise_on_unsuccessful_request(network_response, request)

        return network_response