diff --git a/swh/deposit/api/private/deposit_read.py b/swh/deposit/api/private/deposit_read.py --- a/swh/deposit/api/private/deposit_read.py +++ b/swh/deposit/api/private/deposit_read.py @@ -139,13 +139,24 @@ deposit: Deposit concerned by the data aggregation. Returns: - Dictionary of data representing the deposit to inject in swh. + + Dictionary of metadata information read by the loader, with the following + keys: + + **origin** (Dict): Information about the origin + + **provider** (Dict): the metadata provider information about the deposit + client + + **tool** (Dict): the deposit information + + **raw_metadata** (List[str]): List of raw metadata received for the + deposit + + **deposit** (Dict): deposit information relevant to build the revision """ metadata, raw_metadata = self._metadata_get(deposit) - # Read information metadata - data = {"origin": {"type": "deposit", "url": deposit.origin_url,}} - author_date, commit_date = self._normalize_dates(deposit, metadata) if deposit.parent: @@ -157,8 +168,8 @@ else: parents = [] - data["origin_metadata"] = { - # metadata provider + data = { + "origin": {"type": "deposit", "url": deposit.origin_url}, "provider": { "provider_name": deposit.client.last_name, "provider_url": deposit.client.provider_url, @@ -167,18 +178,17 @@ }, "tool": self.tool, "raw_metadata": raw_metadata, + "deposit": { + "id": deposit.id, + "client": deposit.client.username, + "collection": deposit.collection.name, + "author": SWH_PERSON, + "author_date": author_date, + "committer": SWH_PERSON, + "committer_date": commit_date, + "revision_parents": parents, + }, } - data["deposit"] = { - "id": deposit.id, - "client": deposit.client.username, - "collection": deposit.collection.name, - "author": SWH_PERSON, - "author_date": author_date, - "committer": SWH_PERSON, - "committer_date": commit_date, - "revision_parents": parents, - } - return data def process_get( diff --git a/swh/deposit/tests/api/test_deposit_private_read_metadata.py b/swh/deposit/tests/api/test_deposit_private_read_metadata.py --- a/swh/deposit/tests/api/test_deposit_private_read_metadata.py +++ b/swh/deposit/tests/api/test_deposit_private_read_metadata.py @@ -57,26 +57,24 @@ response = authenticated_client.get(url) assert response.status_code == status.HTTP_200_OK assert response._headers["content-type"][1] == "application/json" - data = response.json() + actual_data = response.json() - expected_meta = { + assert actual_data == { "origin": { "type": "deposit", "url": "https://hal-test.archives-ouvertes.fr/some-external-id", }, - "origin_metadata": { - "raw_metadata": atom_xml_metadata, - "provider": { - "metadata": {}, - "provider_name": "", - "provider_type": "deposit_client", - "provider_url": "https://hal-test.archives-ouvertes.fr/", - }, - "tool": { - "configuration": {"sword_version": "2"}, - "name": "swh-deposit", - "version": __version__, - }, + "raw_metadata": atom_xml_metadata, + "provider": { + "metadata": {}, + "provider_name": "", + "provider_type": "deposit_client", + "provider_url": "https://hal-test.archives-ouvertes.fr/", + }, + "tool": { + "configuration": {"sword_version": "2"}, + "name": "swh-deposit", + "version": __version__, }, "deposit": { "author": SWH_PERSON, @@ -98,8 +96,6 @@ }, } - assert data == expected_meta - def test_read_metadata_revision_with_parent( authenticated_client, deposit_collection, partial_deposit, atom_dataset @@ -117,6 +113,7 @@ authenticated_client, deposit_collection, deposit, atom_xml_data, ) atom_xml_metadata.append(atom_xml_data) + rev_id = "da78a9d4cf1d5d29873693fd496142e3a18c20fa" swhid = "swh:1:rev:%s" % rev_id fake_parent = Deposit( @@ -131,26 +128,23 @@ assert response.status_code == status.HTTP_200_OK assert response._headers["content-type"][1] == "application/json" - data = response.json() - - expected_meta = { + actual_data = response.json() + assert actual_data == { "origin": { "type": "deposit", "url": "https://hal-test.archives-ouvertes.fr/some-external-id", }, - "origin_metadata": { - "raw_metadata": atom_xml_metadata, - "provider": { - "metadata": {}, - "provider_name": "", - "provider_type": "deposit_client", - "provider_url": "https://hal-test.archives-ouvertes.fr/", - }, - "tool": { - "configuration": {"sword_version": "2"}, - "name": "swh-deposit", - "version": __version__, - }, + "raw_metadata": atom_xml_metadata, + "provider": { + "metadata": {}, + "provider_name": "", + "provider_type": "deposit_client", + "provider_url": "https://hal-test.archives-ouvertes.fr/", + }, + "tool": { + "configuration": {"sword_version": "2"}, + "name": "swh-deposit", + "version": __version__, }, "deposit": { "author": SWH_PERSON, @@ -172,8 +166,6 @@ }, } - assert data == expected_meta - def test_read_metadata_3( authenticated_client, deposit_collection, partial_deposit, atom_dataset @@ -208,26 +200,24 @@ assert response.status_code == status.HTTP_200_OK assert response._headers["content-type"][1] == "application/json" - data = response.json() + actual_data = response.json() - expected_meta = { + assert actual_data == { "origin": { "type": "deposit", "url": "https://hal-test.archives-ouvertes.fr/hal-01243065", }, - "origin_metadata": { - "raw_metadata": atom_xml_metadata, - "provider": { - "metadata": {}, - "provider_name": "", - "provider_type": "deposit_client", - "provider_url": "https://hal-test.archives-ouvertes.fr/", - }, - "tool": { - "configuration": {"sword_version": "2"}, - "name": "swh-deposit", - "version": __version__, - }, + "raw_metadata": atom_xml_metadata, + "provider": { + "metadata": {}, + "provider_name": "", + "provider_type": "deposit_client", + "provider_url": "https://hal-test.archives-ouvertes.fr/", + }, + "tool": { + "configuration": {"sword_version": "2"}, + "name": "swh-deposit", + "version": __version__, }, "deposit": { "author": SWH_PERSON, @@ -248,7 +238,6 @@ "revision_parents": [], }, } - assert data == expected_meta def test_read_metadata_4( @@ -272,14 +261,13 @@ assert response.status_code == status.HTTP_200_OK assert response._headers["content-type"][1] == "application/json" - data = response.json() - - expected_origin = { - "type": "deposit", - "url": "https://hal-test.archives-ouvertes.fr/%s" % (deposit.external_id), - } + actual_data = response.json() - expected_origin_metadata = { + assert actual_data == { + "origin": { + "type": "deposit", + "url": "https://hal-test.archives-ouvertes.fr/external-id-partial", + }, "raw_metadata": [codemeta_entry_data], "provider": { "metadata": {}, @@ -292,35 +280,26 @@ "name": "swh-deposit", "version": __version__, }, - } - - expected_deposit_info = { - "author": SWH_PERSON, - "committer": SWH_PERSON, - "committer_date": { - "negative_utc": False, - "offset": 0, - "timestamp": {"microseconds": 0, "seconds": 1459900800}, - }, - "author_date": { - "negative_utc": False, - "offset": 0, - "timestamp": {"microseconds": 0, "seconds": 1459900800}, + "deposit": { + "author": SWH_PERSON, + "committer": SWH_PERSON, + "committer_date": { + "negative_utc": False, + "offset": 0, + "timestamp": {"microseconds": 0, "seconds": 1459900800}, + }, + "author_date": { + "negative_utc": False, + "offset": 0, + "timestamp": {"microseconds": 0, "seconds": 1459900800}, + }, + "client": deposit_collection.name, + "id": deposit.id, + "collection": deposit_collection.name, + "revision_parents": [], }, - "client": deposit_collection.name, - "id": deposit.id, - "collection": deposit_collection.name, - "revision_parents": [], - } - - expected_meta = { - "origin": expected_origin, - "origin_metadata": expected_origin_metadata, - "deposit": expected_deposit_info, } - assert data == expected_meta - def test_read_metadata_5( authenticated_client, deposit_collection, partial_deposit, atom_dataset @@ -353,14 +332,13 @@ assert response.status_code == status.HTTP_200_OK assert response._headers["content-type"][1] == "application/json" - data = response.json() - - expected_origin = { - "type": "deposit", - "url": "https://hal-test.archives-ouvertes.fr/external-id-partial", - } + actual_data = response.json() - expected_origin_metadata = { + assert actual_data == { + "origin": { + "type": "deposit", + "url": "https://hal-test.archives-ouvertes.fr/external-id-partial", + }, "raw_metadata": [codemeta_entry_data], "provider": { "metadata": {}, @@ -373,35 +351,26 @@ "name": "swh-deposit", "version": __version__, }, - } - - expected_deposit_info = { - "author": SWH_PERSON, - "committer": SWH_PERSON, - "committer_date": { - "negative_utc": False, - "offset": 120, - "timestamp": {"microseconds": 0, "seconds": 1493820527}, - }, - "author_date": { - "negative_utc": False, - "offset": 120, - "timestamp": {"microseconds": 0, "seconds": 1428332927}, + "deposit": { + "author": SWH_PERSON, + "committer": SWH_PERSON, + "committer_date": { + "negative_utc": False, + "offset": 120, + "timestamp": {"microseconds": 0, "seconds": 1493820527}, + }, + "author_date": { + "negative_utc": False, + "offset": 120, + "timestamp": {"microseconds": 0, "seconds": 1428332927}, + }, + "client": deposit_collection.name, + "id": deposit.id, + "collection": deposit_collection.name, + "revision_parents": [], }, - "client": deposit_collection.name, - "id": deposit.id, - "collection": deposit_collection.name, - "revision_parents": [], } - expected_meta = { - "origin": expected_origin, - "origin_metadata": expected_origin_metadata, - "deposit": expected_deposit_info, - } - - assert data == expected_meta - def test_access_to_nonexisting_deposit_returns_404_response( authenticated_client, deposit_collection,