Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_update.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from io import BytesIO | from io import BytesIO | ||||
import attr | |||||
from django.core.files.uploadedfile import InMemoryUploadedFile | from django.core.files.uploadedfile import InMemoryUploadedFile | ||||
from django.urls import reverse | from django.urls import reverse | ||||
from rest_framework import status | from rest_framework import status | ||||
from swh.deposit.config import ( | from swh.deposit.config import ( | ||||
DEPOSIT_STATUS_DEPOSITED, | DEPOSIT_STATUS_DEPOSITED, | ||||
DEPOSIT_STATUS_PARTIAL, | DEPOSIT_STATUS_PARTIAL, | ||||
EDIT_SE_IRI, | EDIT_SE_IRI, | ||||
EM_IRI, | EM_IRI, | ||||
APIConfig, | |||||
) | ) | ||||
from swh.deposit.models import Deposit, DepositCollection, DepositRequest | from swh.deposit.models import Deposit, DepositCollection, DepositRequest | ||||
from swh.deposit.parsers import parse_xml | from swh.deposit.parsers import parse_xml | ||||
from swh.deposit.tests.common import check_archive, create_arborescence_archive | from swh.deposit.tests.common import check_archive, create_arborescence_archive | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.identifiers import parse_swhid, swhid | from swh.model.identifiers import parse_swhid, swhid | ||||
from swh.model.model import ( | |||||
MetadataAuthority, | |||||
MetadataAuthorityType, | |||||
MetadataFetcher, | |||||
MetadataTargetType, | |||||
RawExtrinsicMetadata, | |||||
) | |||||
from swh.storage.interface import PagedResult | |||||
def test_replace_archive_to_deposit_is_possible( | def test_replace_archive_to_deposit_is_possible( | ||||
tmp_path, | tmp_path, | ||||
partial_deposit, | partial_deposit, | ||||
deposit_collection, | deposit_collection, | ||||
authenticated_client, | authenticated_client, | ||||
sample_archive, | sample_archive, | ||||
▲ Show 20 Lines • Show All 598 Lines • ▼ Show 20 Lines | ): | ||||
# check we did not touch the other parts | # check we did not touch the other parts | ||||
requests_archive1 = DepositRequest.objects.filter( | requests_archive1 = DepositRequest.objects.filter( | ||||
deposit=complete_deposit, type="archive" | deposit=complete_deposit, type="archive" | ||||
) | ) | ||||
assert len(requests_archive1) == nb_archives | assert len(requests_archive1) == nb_archives | ||||
assert set(actual_existing_requests_archive) == set(requests_archive1) | assert set(actual_existing_requests_archive) == set(requests_archive1) | ||||
# FIXME: Check the metadata storage information created is consistent | # Ensure metadata stored in the metadata storage is consistent | ||||
pass | metadata_authority = MetadataAuthority( | ||||
type=MetadataAuthorityType.DEPOSIT_CLIENT, | |||||
url=complete_deposit.client.provider_url, | |||||
metadata={"name": complete_deposit.client.last_name}, | |||||
) | |||||
actual_authority = swh_storage.metadata_authority_get( | |||||
MetadataAuthorityType.DEPOSIT_CLIENT, url=complete_deposit.client.provider_url | |||||
) | |||||
assert actual_authority == metadata_authority | |||||
config = APIConfig() | |||||
metadata_fetcher = MetadataFetcher( | |||||
name=config.tool["name"], | |||||
version=config.tool["version"], | |||||
metadata=config.tool["configuration"], | |||||
) | |||||
actual_fetcher = swh_storage.metadata_fetcher_get( | |||||
config.tool["name"], config.tool["version"] | |||||
) | |||||
assert actual_fetcher == metadata_fetcher | |||||
directory_swhid = parse_swhid(complete_deposit.swh_id) | |||||
page_results = swh_storage.raw_extrinsic_metadata_get( | |||||
MetadataTargetType.DIRECTORY, directory_swhid, metadata_authority | |||||
) | |||||
assert page_results == PagedResult( | |||||
results=[ | |||||
RawExtrinsicMetadata( | |||||
type=MetadataTargetType.DIRECTORY, | |||||
id=directory_swhid, | |||||
discovery_date=request_meta1.date, | |||||
authority=attr.evolve(metadata_authority, metadata=None), | |||||
fetcher=attr.evolve(metadata_fetcher, metadata=None), | |||||
format="sword-v2-atom-codemeta", | |||||
vlorentz: so that's the raw XML, right? | |||||
Done Inline Actionsyes, in the end, as we were already inconsistent as to what swhid we attached the metadata too (revision with the loader and not the directory), i did not have any more restriction to change this anyways to actually do the right thing... ardumont: yes, in the end, as we were already inconsistent as to what swhid we attached the metadata too… | |||||
metadata=raw_metadata1.encode(), | |||||
) | |||||
], | |||||
next_page_token=None, | |||||
) | |||||
def test_put_update_metadata_done_deposit_failure_swhid_unknown( | def test_put_update_metadata_done_deposit_failure_swhid_unknown( | ||||
tmp_path, | tmp_path, | ||||
authenticated_client, | authenticated_client, | ||||
complete_deposit, | complete_deposit, | ||||
deposit_collection, | deposit_collection, | ||||
Not Done Inline Actionsassert page_results == PagedResult( results=[ RawExtrinsicMetadata( type=MetadataTargetType.DIRECTORY, id=directory_swhid, authority=attr.evolve(metadata_authority, metadata=None), fetcher=attr.evolve(metadata_fetcher, metadata=None), format=..., metadata=..., origin=..., ) ], next_page=token=None, ) vlorentz: ```
assert page_results == PagedResult(
results=[
RawExtrinsicMetadata… | |||||
atom_dataset, | atom_dataset, | ||||
swh_storage, | swh_storage, | ||||
): | ): | ||||
"""Failure: client updates metadata with a SWHID matching the deposit's. Said SWHID does | """Failure: client updates metadata with a SWHID matching the deposit's. Said SWHID does | ||||
not exist in the archive somehow. | not exist in the archive somehow. | ||||
This should not happen though, it is still technically possible so it's | This should not happen though, it is still technically possible so it's | ||||
covered... | covered... | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |
so that's the raw XML, right?