示例#1
0
def copy_metadata_files_api(request):
    """
    Endpoint for adding metadata files to a SIP if using an API key.
    """
    sip_uuid = request.POST.get('sip_uuid')
    paths = request.POST.getlist('source_paths[]')
    return filesystem_ajax_views.copy_metadata_files(sip_uuid, paths)
示例#2
0
def test_copy_metadata_files(mocker):
    # Mock helper that actually copies files from the transfer source locations
    _copy_from_transfer_sources_mock = mocker.patch(
        "components.filesystem_ajax.views._copy_from_transfer_sources",
        return_value=(None, ""),
    )

    # Create a SIP
    sip_uuid = str(uuid.uuid4())
    models.SIP.objects.create(
        uuid=sip_uuid,
        currentpath="%sharedPath%more/path/metadataReminder/mysip-{}/".format(
            sip_uuid),
    )

    # Call the view with a mocked request
    request = mocker.Mock(
        **{
            "POST.get.return_value":
            sip_uuid,
            "POST.getlist.return_value":
            [b64encode_string("locationuuid:/some/path")],
        })
    result = views.copy_metadata_files(request)

    # Verify the contents of the response
    assert result.status_code == 201
    assert result["Content-Type"] == "application/json"
    assert json.loads(result.content) == {
        "message": "Metadata files added successfully.",
        "error": None,
    }

    # Verify the copier helper was called with the right parameters
    _copy_from_transfer_sources_mock.assert_called_once_with(
        ["locationuuid:/some/path"],
        "more/path/metadataReminder/mysip-{}/metadata".format(sip_uuid),
    )
示例#3
0
def copy_metadata_files_api(request):
    """
    Endpoint for adding metadata files to a SIP if using an API key.
    """
    return filesystem_ajax_views.copy_metadata_files(request)