def test_complete_multipart_upload_missing_key(app, indexd_client): """ Test BlankIndex complete_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.complete_multipart_upload( key="some key", uploadId="some id", parts=[ { "Etag": "1234567", "PartNumber": 1 }, { "Etag": "4321234", "PartNumber": 2 }, ], )
def complete_multipart_upload(): """ Complete multipart upload """ params = flask.request.get_json() if not params: raise UserError("wrong Content-Type; expected application/json") missing = {"key", "uploadId", "parts"}.difference(set(params)) if missing: raise UserError("missing required arguments: {}".format(list(missing))) 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, ) try: BlankIndex.complete_multipart_upload( params["key"], params["uploadId"], params["parts"], expires_in=expires_in ), except InternalError as e: return flask.jsonify({"message": e.message}), e.code return flask.jsonify({"message": "OK"}), 200
def test_complete_multipart_upload(app, indexd_client): """ Test BlankIndex complete_multipart_upload """ uploader = MagicMock() blank_index = BlankIndex(uploader=uploader) assert blank_index with patch( "fence.blueprints.data.indexd.S3IndexedFileLocation.complete_multipart_upload" ): blank_index.complete_multipart_upload( key="some key", uploadId="some id", parts=[ { "Etag": "1234567", "PartNumber": 1 }, { "Etag": "4321234", "PartNumber": 2 }, ], )