Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9312060
D274.id928.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Subscribers
None
D274.id928.diff
View Options
diff --git a/swh/deposit/api/private/deposit_check.py b/swh/deposit/api/private/deposit_check.py
--- a/swh/deposit/api/private/deposit_check.py
+++ b/swh/deposit/api/private/deposit_check.py
@@ -11,7 +11,7 @@
from ..common import SWHGetDepositAPI, SWHPrivateAPIView
from ...config import DEPOSIT_STATUS_READY, DEPOSIT_STATUS_REJECTED
-from ...config import ARCHIVE_TYPE
+from ...config import ARCHIVE_TYPE, METADATA_TYPE
from ...models import Deposit, DepositRequest
@@ -21,6 +21,7 @@
Only GET is supported.
"""
+
def deposit_requests(self, deposit):
"""Given a deposit, yields its associated deposit_request
@@ -62,7 +63,21 @@
True if metadata is ok, False otherwise.
"""
- # FIXME: Define checks to implement
+ must_meta = ['url', 'external_identifier', ['name', 'title'], 'author']
+ # checks only for must metadata on all metadata requests
+ for mm in must_meta:
+ found = False
+ for k in metadata:
+ if isinstance(mm, list):
+ for p in mm:
+ if p in k:
+ found = True
+ break
+ elif mm in k:
+ found = True
+ break
+ if not found:
+ return False
return True
def process_get(self, req, collection_name, deposit_id):
@@ -79,16 +94,18 @@
"""
deposit = Deposit.objects.get(pk=deposit_id)
+ all_metadata = {}
# will check each deposit request for the deposit
for dr in self.deposit_requests(deposit):
if dr.type.name == ARCHIVE_TYPE:
deposit_status = self._check_archive(dr.archive)
- else:
- deposit_status = self._check_metadata(dr.metadata)
-
+ elif dr.type.name == METADATA_TYPE:
+ # aggregating all metadata requests for check on complete set
+ all_metadata.update(dr.metadata)
if not deposit_status:
break
+ deposit_status = self._check_metadata(all_metadata)
# if problem in any deposit requests, the deposit is rejected
if not deposit_status:
deposit.status = DEPOSIT_STATUS_REJECTED
diff --git a/swh/deposit/tests/api/test_deposit_check.py b/swh/deposit/tests/api/test_deposit_check.py
--- a/swh/deposit/tests/api/test_deposit_check.py
+++ b/swh/deposit/tests/api/test_deposit_check.py
@@ -33,7 +33,9 @@
"""Proper deposit should succeed the checks (-> status ready)
"""
- deposit_id = self.create_simple_binary_deposit(status_partial=False)
+ deposit_id = self.create_simple_binary_deposit(status_partial=True)
+ deposit_id = self.update_binary_deposit(deposit_id,
+ status_partial=False)
deposit = Deposit.objects.get(pk=deposit_id)
self.assertEquals(deposit.status, DEPOSIT_STATUS_READY_FOR_CHECKS)
@@ -69,3 +71,28 @@
self.assertEqual(data['status'], DEPOSIT_STATUS_REJECTED)
deposit = Deposit.objects.get(pk=deposit.id)
self.assertEquals(deposit.status, DEPOSIT_STATUS_REJECTED)
+
+ @istest
+ def check_deposit_metadata_ok(self):
+ """Proper deposit should succeed the checks (-> status ready)
+ with all **MUST** metadata
+
+ using the codemeta metadata test set
+ """
+ deposit_id = self.create_simple_binary_deposit(status_partial=True)
+ deposit_id_metadata = self.add_metadata_to_deposit(deposit_id)
+ self.assertEquals(deposit_id, deposit_id_metadata)
+
+ deposit = Deposit.objects.get(pk=deposit_id)
+ self.assertEquals(deposit.status, DEPOSIT_STATUS_READY_FOR_CHECKS)
+
+ url = reverse(PRIVATE_CHECK_DEPOSIT,
+ args=[self.collection.name, deposit.id])
+
+ response = self.client.get(url)
+
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ data = json.loads(response.content.decode('utf-8'))
+ self.assertEqual(data['status'], DEPOSIT_STATUS_READY)
+ deposit = Deposit.objects.get(pk=deposit.id)
+ self.assertEquals(deposit.status, DEPOSIT_STATUS_READY)
diff --git a/swh/deposit/tests/common.py b/swh/deposit/tests/common.py
--- a/swh/deposit/tests/common.py
+++ b/swh/deposit/tests/common.py
@@ -95,6 +95,16 @@
self.archive = create_arborescence_zip(
self.root_path, 'archive1', 'file1', b'some content in file')
+ self.atom_entry = b"""<?xml version="1.0"?>
+ <entry xmlns="http://www.w3.org/2005/Atom">
+ <title>Awesome Compiler</title>
+ <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
+ <external_identifier>1785io25c695</external_identifier>
+ <updated>2017-10-07T15:17:08Z</updated>
+ <author>some awesome author</author>
+ <url>http://test.test.fr</url>
+ </entry>"""
+
def tearDown(self):
super().tearDown()
shutil.rmtree(self.root_path)
@@ -141,6 +151,22 @@
'{http://www.w3.org/2005/Atom}deposit_id']
return deposit_id
+ def update_binary_deposit(self, deposit_id, status_partial=False):
+ # update existing deposit with atom entry metadata
+ response = self.client.post(
+ reverse(EDIT_SE_IRI, args=[self.collection.name, deposit_id]),
+ content_type='application/atom+xml;type=entry',
+ data=self.codemeta_entry_data1,
+ HTTP_SLUG='external-id',
+ HTTP_IN_PROGRESS=status_partial)
+
+ # then
+ # assert response.status_code == status.HTTP_201_CREATED
+ response_content = parse_xml(BytesIO(response.content))
+ deposit_id = response_content[
+ '{http://www.w3.org/2005/Atom}deposit_id']
+ return deposit_id
+
@attr('fs')
class BasicTestCase(TestCase):
@@ -220,14 +246,14 @@
super().setUp()
self.atom_entry_data0 = b"""<?xml version="1.0"?>
-<entry xmlns="http://www.w3.org/2005/Atom">
- <external_identifier>some-external-id</external_identifier>
-</entry>"""
+ <entry xmlns="http://www.w3.org/2005/Atom">
+ <external_identifier>some-external-id</external_identifier>
+ </entry>"""
self.atom_entry_data1 = b"""<?xml version="1.0"?>
-<entry xmlns="http://www.w3.org/2005/Atom">
- <external_identifier>anotherthing</external_identifier>
-</entry>"""
+ <entry xmlns="http://www.w3.org/2005/Atom">
+ <external_identifier>anotherthing</external_identifier>
+ </entry>"""
self.atom_entry_data2 = b"""<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom">
@@ -236,12 +262,14 @@
<external_identifier>1785io25c695</external_identifier>
<updated>2017-10-07T15:17:08Z</updated>
<author>some awesome author</author>
+ <url>http://test.test.fr</url>
</entry>"""
self.codemeta_entry_data0 = b"""<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:codemeta="https://doi.org/10.5063/SCHEMA/CODEMETA-2.0">
<title>Awesome Compiler</title>
+ <url>http://test.test.fr</url>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<external_identifier>1785io25c695</external_identifier>
<updated>2017-10-07T15:17:08Z</updated>
@@ -278,6 +306,9 @@
<name>HAL</name>
<email>hal@ccsd.cnrs.fr</email>
</author>
+ <codemeta:author>
+ <codemeta:name>Morane Gruenpeter</codemeta:name>
+ </codemeta:author>
</entry>"""
def create_invalid_deposit(self):
diff --git a/swh/deposit/tests/loader/test_checker.py b/swh/deposit/tests/loader/test_checker.py
--- a/swh/deposit/tests/loader/test_checker.py
+++ b/swh/deposit/tests/loader/test_checker.py
@@ -38,6 +38,8 @@
"""
# 1. create a deposit with archive and metadata
deposit_id = self.create_simple_binary_deposit()
+ deposit_id = self.update_binary_deposit(deposit_id,
+ status_partial=False)
args = [self.collection.name, deposit_id]
deposit_check_url = reverse(PRIVATE_CHECK_DEPOSIT, args=args)
diff --git a/swh/deposit/tests/loader/test_loader.py b/swh/deposit/tests/loader/test_loader.py
--- a/swh/deposit/tests/loader/test_loader.py
+++ b/swh/deposit/tests/loader/test_loader.py
@@ -268,6 +268,9 @@
codemeta + 'name':
'CeCILL Free Software License Agreement v1.1'
},
+ codemeta + 'author': {
+ codemeta + 'name': 'Morane Gruenpeter'
+ },
codemeta + 'programmingLanguage': 'C',
codemeta + 'applicationCategory': 'test',
codemeta + 'dateCreated': '2017-05-03T16:08:47+02:00',
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jul 2, 10:41 AM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221471
Attached To
D274: Add pre-load metadata checks
Event Timeline
Log In to Comment