Example #1
0
def test_init_multipart_upload(app, indexd_client):
    """
    Test BlankIndex init_multipart_upload
    """
    uploader = MagicMock()
    blank_index = BlankIndex(uploader=uploader)
    assert blank_index
    with patch(
            "fence.blueprints.data.indexd.S3IndexedFileLocation.init_multipart_upload"
    ):
        blank_index.init_multipart_upload(key="some key")
Example #2
0
def test_init_multipart_upload_missing_configuration_key(app, indexd_client):
    """
    test BlankIndex init_multipart_upload with a missing configuration key
    """
    uploader = MagicMock()
    current_app = flask.current_app
    expected_value = copy.deepcopy(current_app.config)
    del expected_value["DATA_UPLOAD_BUCKET"]

    with patch.object(current_app, "config", expected_value):
        assert current_app.config == expected_value
        blank_index = BlankIndex(uploader=uploader)
        assert blank_index
        with pytest.raises(InternalError):
            blank_index.init_multipart_upload(key="some key")
Example #3
0
def init_multipart_upload():
    """
    Initialize a multipart upload request
    """
    params = flask.request.get_json()
    if not params:
        raise UserError("wrong Content-Type; expected application/json")
    if "file_name" not in params:
        raise UserError("missing required argument `file_name`")
    blank_index = BlankIndex(file_name=params["file_name"])

    default_expires_in = flask.current_app.config.get("MAX_PRESIGNED_URL_TTL", 3600)
    expires_in = get_valid_expiration(
        params.get("expires_in"),
        max_limit=default_expires_in,
        default=default_expires_in,
    )

    response = {
        "guid": blank_index.guid,
        "uploadId": BlankIndex.init_multipart_upload(
            blank_index.guid + "/" + params["file_name"], expires_in=expires_in
        ),
    }
    return flask.jsonify(response), 201