Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9696313
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
34 KB
Subscribers
None
View Options
diff --git a/PKG-INFO b/PKG-INFO
index c5772c10..fd471a3c 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,10 +1,10 @@
Metadata-Version: 1.0
Name: swh.deposit
-Version: 0.0.60
+Version: 0.0.61
Summary: Software Heritage Deposit Server
Home-page: https://forge.softwareheritage.org/source/swh-deposit/
Author: Software Heritage developers
Author-email: swh-devel@inria.fr
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
diff --git a/swh.deposit.egg-info/PKG-INFO b/swh.deposit.egg-info/PKG-INFO
index c5772c10..fd471a3c 100644
--- a/swh.deposit.egg-info/PKG-INFO
+++ b/swh.deposit.egg-info/PKG-INFO
@@ -1,10 +1,10 @@
Metadata-Version: 1.0
Name: swh.deposit
-Version: 0.0.60
+Version: 0.0.61
Summary: Software Heritage Deposit Server
Home-page: https://forge.softwareheritage.org/source/swh-deposit/
Author: Software Heritage developers
Author-email: swh-devel@inria.fr
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
diff --git a/swh.deposit.egg-info/SOURCES.txt b/swh.deposit.egg-info/SOURCES.txt
index e6fcdc9d..92f96c1e 100644
--- a/swh.deposit.egg-info/SOURCES.txt
+++ b/swh.deposit.egg-info/SOURCES.txt
@@ -1,164 +1,166 @@
.gitignore
AUTHORS
LICENSE
MANIFEST.in
Makefile
Makefile.local
README.md
requirements-swh.txt
requirements-test.txt
requirements.txt
setup.py
version.txt
bin/Makefile
bin/content.sh
bin/create_deposit.sh
bin/create_deposit_atom.sh
bin/create_deposit_with_metadata.sh
bin/default-setup
bin/download-deposit-archive.sh
bin/home.sh
bin/replace-deposit-archive.sh
bin/service-document.sh
bin/status.sh
bin/swh-deposit
bin/update-deposit-with-another-archive.sh
bin/update-status.sh
debian/changelog
debian/compat
debian/control
debian/copyright
debian/rules
debian/source/format
docs/.gitignore
docs/Makefile
docs/conf.py
docs/dev-info.rst
docs/getting-started.rst
docs/index.rst
docs/metadata.rst
docs/spec-api.rst
docs/sys-info.rst
docs/_static/.placeholder
docs/_templates/.placeholder
docs/endpoints/collection.rst
docs/endpoints/content.rst
docs/endpoints/service-document.rst
docs/endpoints/status.rst
docs/endpoints/update-media.rst
docs/endpoints/update-metadata.rst
docs/images/deposit-create-chart.png
docs/images/deposit-delete-chart.png
docs/images/deposit-update-chart.png
docs/specs/blueprint.rst
docs/specs/metadata_example.xml
docs/specs/spec-loading.rst
docs/specs/spec-meta-deposit.rst
docs/specs/spec-sparse-deposit.rst
docs/specs/specs.rst
docs/specs/swh.xsd
resources/deposit/server.yml
swh/__init__.py
swh/manage.py
swh.deposit.egg-info/PKG-INFO
swh.deposit.egg-info/SOURCES.txt
swh.deposit.egg-info/dependency_links.txt
swh.deposit.egg-info/requires.txt
swh.deposit.egg-info/top_level.txt
swh/deposit/__init__.py
swh/deposit/apps.py
swh/deposit/auth.py
swh/deposit/config.py
swh/deposit/create_user.py
swh/deposit/errors.py
swh/deposit/models.py
swh/deposit/parsers.py
swh/deposit/signals.py
swh/deposit/urls.py
swh/deposit/utils.py
swh/deposit/wsgi.py
swh/deposit/api/__init__.py
swh/deposit/api/common.py
swh/deposit/api/deposit.py
swh/deposit/api/deposit_content.py
swh/deposit/api/deposit_status.py
swh/deposit/api/deposit_update.py
swh/deposit/api/service_document.py
swh/deposit/api/urls.py
swh/deposit/api/private/__init__.py
swh/deposit/api/private/deposit_check.py
+swh/deposit/api/private/deposit_list.py
swh/deposit/api/private/deposit_read.py
swh/deposit/api/private/deposit_update_status.py
swh/deposit/api/private/urls.py
swh/deposit/client/__init__.py
swh/deposit/client/cli.py
swh/deposit/fixtures/__init__.py
swh/deposit/fixtures/deposit_data.yaml
swh/deposit/loader/__init__.py
swh/deposit/loader/checker.py
swh/deposit/loader/loader.py
swh/deposit/loader/scheduler.py
swh/deposit/loader/tasks.py
swh/deposit/migrations/0001_initial.py
swh/deposit/migrations/0002_depositrequest_archive.py
swh/deposit/migrations/0003_temporaryarchive.py
swh/deposit/migrations/0004_delete_temporaryarchive.py
swh/deposit/migrations/0005_auto_20171019_1436.py
swh/deposit/migrations/0006_depositclient_url.py
swh/deposit/migrations/0007_auto_20171129_1609.py
swh/deposit/migrations/0008_auto_20171130_1513.py
swh/deposit/migrations/0009_deposit_parent.py
swh/deposit/migrations/0010_auto_20180110_0953.py
swh/deposit/migrations/0011_auto_20180115_1510.py
swh/deposit/migrations/0012_deposit_status_detail.py
swh/deposit/migrations/0013_depositrequest_raw_metadata.py
swh/deposit/migrations/0014_auto_20180720_1221.py
swh/deposit/migrations/__init__.py
swh/deposit/settings/__init__.py
swh/deposit/settings/common.py
swh/deposit/settings/development.py
swh/deposit/settings/production.py
swh/deposit/settings/testing.py
swh/deposit/static/robots.txt
swh/deposit/static/css/bootstrap-responsive.min.css
swh/deposit/static/css/style.css
swh/deposit/static/img/arrow-up-small.png
swh/deposit/static/img/swh-logo-deposit.png
swh/deposit/static/img/swh-logo-deposit.svg
swh/deposit/static/img/icons/swh-logo-32x32.png
swh/deposit/static/img/icons/swh-logo-deposit-180x180.png
swh/deposit/static/img/icons/swh-logo-deposit-192x192.png
swh/deposit/static/img/icons/swh-logo-deposit-270x270.png
swh/deposit/templates/__init__.py
swh/deposit/templates/homepage.html
swh/deposit/templates/layout.html
swh/deposit/templates/deposit/__init__.py
swh/deposit/templates/deposit/content.xml
swh/deposit/templates/deposit/deposit_receipt.xml
swh/deposit/templates/deposit/error.xml
swh/deposit/templates/deposit/service_document.xml
swh/deposit/templates/deposit/status.xml
swh/deposit/templates/rest_framework/api.html
swh/deposit/tests/__init__.py
swh/deposit/tests/common.py
swh/deposit/tests/test_utils.py
swh/deposit/tests/api/__init__.py
swh/deposit/tests/api/test_common.py
swh/deposit/tests/api/test_deposit.py
swh/deposit/tests/api/test_deposit_atom.py
swh/deposit/tests/api/test_deposit_binary.py
swh/deposit/tests/api/test_deposit_check.py
swh/deposit/tests/api/test_deposit_delete.py
+swh/deposit/tests/api/test_deposit_list.py
swh/deposit/tests/api/test_deposit_multipart.py
swh/deposit/tests/api/test_deposit_read_archive.py
swh/deposit/tests/api/test_deposit_read_metadata.py
swh/deposit/tests/api/test_deposit_status.py
swh/deposit/tests/api/test_deposit_update.py
swh/deposit/tests/api/test_deposit_update_status.py
swh/deposit/tests/api/test_parser.py
swh/deposit/tests/api/test_service_document.py
swh/deposit/tests/loader/__init__.py
swh/deposit/tests/loader/common.py
swh/deposit/tests/loader/test_checker.py
swh/deposit/tests/loader/test_client.py
swh/deposit/tests/loader/test_loader.py
\ No newline at end of file
diff --git a/swh/deposit/api/private/deposit_list.py b/swh/deposit/api/private/deposit_list.py
new file mode 100644
index 00000000..3a649737
--- /dev/null
+++ b/swh/deposit/api/private/deposit_list.py
@@ -0,0 +1,37 @@
+# Copyright (C) 2018 The Software Heritage developers
+# See the AUTHORS file at the top-level directory of this distribution
+# License: GNU General Public License version 3, or any later version
+# See top-level LICENSE file for more information
+
+
+from rest_framework.generics import ListAPIView
+from rest_framework.pagination import PageNumberPagination
+from rest_framework import serializers
+
+from ...models import Deposit
+
+
+class DefaultPagination(PageNumberPagination):
+ page_size = 100
+ page_size_query_param = 'page_size'
+
+
+class DepositSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = Deposit
+ fields = ('id', 'reception_date', 'complete_date', 'status',
+ 'collection', 'external_id', 'client',
+ 'swh_id', 'swh_id_context',
+ 'swh_anchor_id', 'swh_anchor_id_context',
+ 'status', 'status_detail', 'parent')
+
+
+class DepositList(ListAPIView):
+ """Deposit request class to list the deposit's status per page.
+
+ HTTP verbs supported: GET
+
+ """
+ queryset = Deposit.objects.all().order_by('id')
+ serializer_class = DepositSerializer
+ pagination_class = DefaultPagination
diff --git a/swh/deposit/api/private/urls.py b/swh/deposit/api/private/urls.py
index 3a7e532a..14335f25 100644
--- a/swh/deposit/api/private/urls.py
+++ b/swh/deposit/api/private/urls.py
@@ -1,37 +1,41 @@
-# Copyright (C) 2017 The Software Heritage developers
+# Copyright (C) 2017-2018 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from django.conf.urls import url
-from ...config import PRIVATE_GET_RAW_CONTENT
-from ...config import PRIVATE_PUT_DEPOSIT, PRIVATE_GET_DEPOSIT_METADATA
-from ...config import PRIVATE_CHECK_DEPOSIT
+from ...config import (
+ PRIVATE_GET_RAW_CONTENT, PRIVATE_PUT_DEPOSIT, PRIVATE_GET_DEPOSIT_METADATA,
+ PRIVATE_CHECK_DEPOSIT, PRIVATE_LIST_DEPOSITS
+)
from .deposit_read import SWHDepositReadArchives
from .deposit_read import SWHDepositReadMetadata
from .deposit_update_status import SWHUpdateStatusDeposit
from .deposit_check import SWHChecksDeposit
+from .deposit_list import DepositList
urlpatterns = [
# Retrieve deposit's raw archives' content
# -> GET
url(r'^(?P<collection_name>[^/]+)/(?P<deposit_id>[^/]+)/raw/$',
SWHDepositReadArchives.as_view(),
name=PRIVATE_GET_RAW_CONTENT),
# Update deposit's status
# -> PUT
url(r'^(?P<collection_name>[^/]+)/(?P<deposit_id>[^/]+)/update/$',
SWHUpdateStatusDeposit.as_view(),
name=PRIVATE_PUT_DEPOSIT),
# Retrieve metadata information on a specific deposit
# -> GET
url(r'^(?P<collection_name>[^/]+)/(?P<deposit_id>[^/]+)/meta/$',
SWHDepositReadMetadata.as_view(),
name=PRIVATE_GET_DEPOSIT_METADATA),
# Check archive and metadata information on a specific deposit
# -> GET
url(r'^(?P<collection_name>[^/]+)/(?P<deposit_id>[^/]+)/check/$',
SWHChecksDeposit.as_view(),
name=PRIVATE_CHECK_DEPOSIT),
+ url(r'^deposits/$', DepositList.as_view(),
+ name=PRIVATE_LIST_DEPOSITS)
]
diff --git a/swh/deposit/config.py b/swh/deposit/config.py
index fca74e40..2e6b35e1 100644
--- a/swh/deposit/config.py
+++ b/swh/deposit/config.py
@@ -1,100 +1,101 @@
# Copyright (C) 2017-2018 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import os
import logging
from swh.core.config import SWHConfig
from swh.scheduler import get_scheduler
# IRIs (Internationalized Resource identifier) sword 2.0 specified
EDIT_SE_IRI = 'edit_se_iri'
EM_IRI = 'em_iri'
CONT_FILE_IRI = 'cont_file_iri'
SD_IRI = 'servicedocument'
COL_IRI = 'upload'
STATE_IRI = 'state_iri'
PRIVATE_GET_RAW_CONTENT = 'private-download'
PRIVATE_CHECK_DEPOSIT = 'check-deposit'
PRIVATE_PUT_DEPOSIT = 'private-update'
PRIVATE_GET_DEPOSIT_METADATA = 'private-read'
+PRIVATE_LIST_DEPOSITS = 'private-deposit-list'
ARCHIVE_KEY = 'archive'
METADATA_KEY = 'metadata'
RAW_METADATA_KEY = 'raw-metadata'
ARCHIVE_TYPE = 'archive'
METADATA_TYPE = 'metadata'
AUTHORIZED_PLATFORMS = ['development', 'production', 'testing']
DEPOSIT_STATUS_REJECTED = 'rejected'
DEPOSIT_STATUS_PARTIAL = 'partial'
DEPOSIT_STATUS_DEPOSITED = 'deposited'
DEPOSIT_STATUS_VERIFIED = 'verified'
DEPOSIT_STATUS_LOAD_SUCCESS = 'done'
DEPOSIT_STATUS_LOAD_FAILURE = 'failed'
# Revision author for deposit
SWH_PERSON = {
'name': 'Software Heritage',
'fullname': 'Software Heritage',
'email': 'robot@softwareheritage.org'
}
def setup_django_for(platform):
"""Setup function for command line tools (swh.deposit.create_user,
swh.deposit.scheduler.cli) to initialize the needed db access.
Note:
Do not import any django related module prior to this function
call. Otherwise, this will raise an
django.core.exceptions.ImproperlyConfigured error message.
Args:
platform (str): the platform the scheduling is running
Raises:
ValueError in case of wrong platform inputs.
"""
if platform not in AUTHORIZED_PLATFORMS:
raise ValueError('Platform should be one of %s' % AUTHORIZED_PLATFORMS)
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
'swh.deposit.settings.%s' % platform)
import django
django.setup()
class SWHDefaultConfig(SWHConfig):
"""Mixin intended to enrich views with SWH configuration.
"""
CONFIG_BASE_FILENAME = 'deposit/server'
DEFAULT_CONFIG = {
'max_upload_size': ('int', 209715200),
'checks': ('bool', True),
'scheduler': ('dict', {
'cls': 'remote',
'args': {
'url': 'http://localhost:5008/'
}
})
}
ADDITIONAL_CONFIG = {}
def __init__(self, **config):
super().__init__()
self.config = self.parse_config_file(
additional_configs=[self.ADDITIONAL_CONFIG])
self.config.update(config)
self.log = logging.getLogger('swh.deposit')
if self.config['checks']:
self.scheduler = get_scheduler(**self.config['scheduler'])
diff --git a/swh/deposit/tests/api/test_deposit_check.py b/swh/deposit/tests/api/test_deposit_check.py
index e2d15831..9ce5d1c5 100644
--- a/swh/deposit/tests/api/test_deposit_check.py
+++ b/swh/deposit/tests/api/test_deposit_check.py
@@ -1,247 +1,246 @@
# Copyright (C) 2017-2018 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-import json
import unittest
from django.core.urlresolvers import reverse
from nose.tools import istest
from nose.plugins.attrib import attr
from rest_framework import status
from rest_framework.test import APITestCase
from swh.deposit.config import (
DEPOSIT_STATUS_VERIFIED, PRIVATE_CHECK_DEPOSIT,
DEPOSIT_STATUS_DEPOSITED, DEPOSIT_STATUS_REJECTED
)
from swh.deposit.api.private.deposit_check import (
SWHChecksDeposit, MANDATORY_ARCHIVE_INVALID,
MANDATORY_FIELDS_MISSING, INCOMPATIBLE_URL_FIELDS,
MANDATORY_ARCHIVE_UNSUPPORTED, ALTERNATE_FIELDS_MISSING,
MANDATORY_ARCHIVE_MISSING
)
from swh.deposit.models import Deposit
from ..common import BasicTestCase, WithAuthTestCase, CommonCreationRoutine
from ..common import FileSystemCreationRoutine
@attr('fs')
class CheckDepositTest(APITestCase, WithAuthTestCase,
BasicTestCase, CommonCreationRoutine,
FileSystemCreationRoutine):
"""Check deposit endpoints.
"""
def setUp(self):
super().setUp()
@istest
def deposit_ok(self):
"""Proper deposit should succeed the checks (-> status ready)
"""
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_DEPOSITED)
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'))
+ data = response.json()
self.assertEqual(data['status'], DEPOSIT_STATUS_VERIFIED)
deposit = Deposit.objects.get(pk=deposit.id)
self.assertEquals(deposit.status, DEPOSIT_STATUS_VERIFIED)
@istest
def deposit_invalid_tarball(self):
"""Deposit with tarball (of 1 tarball) should fail the checks: rejected
"""
for archive_extension in ['zip', 'tar', 'tar.gz', 'tar.bz2', 'tar.xz']:
deposit_id = self.create_deposit_archive_with_archive(
archive_extension)
deposit = Deposit.objects.get(pk=deposit_id)
self.assertEquals(DEPOSIT_STATUS_DEPOSITED, deposit.status)
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'))
+ data = response.json()
self.assertEqual(data['status'], DEPOSIT_STATUS_REJECTED)
details = data['details']
# archive checks failure
self.assertEqual(len(details['archive']), 1)
self.assertEqual(details['archive'][0]['summary'],
MANDATORY_ARCHIVE_INVALID)
deposit = Deposit.objects.get(pk=deposit.id)
self.assertEquals(deposit.status, DEPOSIT_STATUS_REJECTED)
@istest
def deposit_ko_missing_tarball(self):
"""Deposit without archive should fail the checks: rejected
"""
deposit_id = self.create_deposit_ready() # no archive, only atom
deposit = Deposit.objects.get(pk=deposit_id)
self.assertEquals(DEPOSIT_STATUS_DEPOSITED, deposit.status)
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'))
+ data = response.json()
self.assertEqual(data['status'], DEPOSIT_STATUS_REJECTED)
details = data['details']
# archive checks failure
self.assertEqual(len(details['archive']), 1)
self.assertEqual(details['archive'][0]['summary'],
MANDATORY_ARCHIVE_MISSING)
deposit = Deposit.objects.get(pk=deposit.id)
self.assertEquals(deposit.status, DEPOSIT_STATUS_REJECTED)
@istest
def deposit_ko_unsupported_tarball(self):
"""Deposit with an unsupported tarball should fail the checks: rejected
"""
deposit_id = self.create_deposit_with_invalid_archive()
deposit = Deposit.objects.get(pk=deposit_id)
self.assertEquals(DEPOSIT_STATUS_DEPOSITED, deposit.status)
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'))
+ data = response.json()
self.assertEqual(data['status'], DEPOSIT_STATUS_REJECTED)
details = data['details']
# archive checks failure
self.assertEqual(len(details['archive']), 1)
self.assertEqual(details['archive'][0]['summary'],
MANDATORY_ARCHIVE_UNSUPPORTED)
# metadata check failure
self.assertEqual(len(details['metadata']), 2)
mandatory = details['metadata'][0]
self.assertEqual(mandatory['summary'], MANDATORY_FIELDS_MISSING)
self.assertEqual(set(mandatory['fields']),
set(['url', 'external_identifier', 'author']))
alternate = details['metadata'][1]
self.assertEqual(alternate['summary'], ALTERNATE_FIELDS_MISSING)
self.assertEqual(alternate['fields'], ['name or title'])
# url check failure
self.assertEqual(details['url']['summary'], INCOMPATIBLE_URL_FIELDS)
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_DEPOSITED)
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'))
+ data = response.json()
self.assertEqual(data['status'], DEPOSIT_STATUS_VERIFIED)
deposit = Deposit.objects.get(pk=deposit.id)
self.assertEquals(deposit.status, DEPOSIT_STATUS_VERIFIED)
class CheckMetadata(unittest.TestCase, SWHChecksDeposit):
@istest
def check_metadata_ok(self):
actual_check, detail = self._check_metadata({
'url': 'something',
'external_identifier': 'something-else',
'name': 'foo',
'author': 'someone',
})
self.assertTrue(actual_check)
self.assertIsNone(detail)
@istest
def check_metadata_ok2(self):
actual_check, detail = self._check_metadata({
'url': 'something',
'external_identifier': 'something-else',
'title': 'bar',
'author': 'someone',
})
self.assertTrue(actual_check)
self.assertIsNone(detail)
@istest
def check_metadata_ko(self):
"""Missing optional field should be caught
"""
actual_check, error_detail = self._check_metadata({
'url': 'something',
'external_identifier': 'something-else',
'author': 'someone',
})
expected_error = {
'metadata': [{
'summary': 'Mandatory alternate fields are missing',
'fields': ['name or title'],
}]
}
self.assertFalse(actual_check)
self.assertEqual(error_detail, expected_error)
@istest
def check_metadata_ko2(self):
"""Missing mandatory fields should be caught
"""
actual_check, error_detail = self._check_metadata({
'url': 'something',
'external_identifier': 'something-else',
'title': 'foobar',
})
expected_error = {
'metadata': [{
'summary': 'Mandatory fields are missing',
'fields': ['author'],
}]
}
self.assertFalse(actual_check)
self.assertEqual(error_detail, expected_error)
diff --git a/swh/deposit/tests/api/test_deposit_list.py b/swh/deposit/tests/api/test_deposit_list.py
new file mode 100644
index 00000000..401f04a5
--- /dev/null
+++ b/swh/deposit/tests/api/test_deposit_list.py
@@ -0,0 +1,64 @@
+# Copyright (C) 2017-2018 The Software Heritage developers
+# See the AUTHORS file at the top-level directory of this distribution
+# License: GNU General Public License version 3, or any later version
+# See top-level LICENSE file for more information
+
+from django.core.urlresolvers import reverse
+from nose.tools import istest
+from nose.plugins.attrib import attr
+from rest_framework import status
+from rest_framework.test import APITestCase
+
+from ...config import DEPOSIT_STATUS_PARTIAL, PRIVATE_LIST_DEPOSITS
+from ..common import BasicTestCase, WithAuthTestCase, CommonCreationRoutine
+
+
+@attr('fs')
+class CheckDepositStatusesTest(APITestCase, WithAuthTestCase,
+ BasicTestCase, CommonCreationRoutine):
+ """Check deposit statuses endpoints.
+
+ """
+ def setUp(self):
+ super().setUp()
+
+ @istest
+ def deposit_list(self):
+ """Deposit list api should return the deposits
+
+ """
+ deposit_id = self.create_deposit_partial()
+ deposit_id2 = self.create_deposit_partial()
+
+ # NOTE: does not work as documented
+ # https://docs.djangoproject.com/en/1.11/ref/urlresolvers/#django.core.urlresolvers.reverse # noqa
+ # url = reverse(PRIVATE_LIST_DEPOSITS, kwargs={'page_size': 1})
+ main_url = reverse(PRIVATE_LIST_DEPOSITS)
+ url = '%s?page_size=1' % main_url
+ response = self.client.get(url)
+
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ data = response.json()
+ self.assertEqual(data['count'], 2) # 2 deposits
+ expected_next = '%s?page=2&page_size=1' % main_url
+ self.assertTrue(data['next'].endswith(expected_next))
+ self.assertIsNone(data['previous'])
+ self.assertEqual(len(data['results']), 1) # page of size 1
+ deposit = data['results'][0]
+ self.assertEquals(deposit['id'], deposit_id)
+ self.assertEquals(deposit['status'], DEPOSIT_STATUS_PARTIAL)
+
+ # then 2nd page
+ response2 = self.client.get(expected_next)
+
+ self.assertEqual(response2.status_code, status.HTTP_200_OK)
+ data2 = response2.json()
+
+ self.assertEqual(data2['count'], 2) # still 2 deposits
+ self.assertIsNone(data2['next'])
+ expected_previous = '%s?page_size=1' % main_url
+ self.assertTrue(data2['previous'].endswith(expected_previous))
+ self.assertEqual(len(data2['results']), 1) # page of size 1
+ deposit2 = data2['results'][0]
+ self.assertEquals(deposit2['id'], deposit_id2)
+ self.assertEquals(deposit2['status'], DEPOSIT_STATUS_PARTIAL)
diff --git a/swh/deposit/tests/api/test_deposit_read_metadata.py b/swh/deposit/tests/api/test_deposit_read_metadata.py
index bcc546f3..15653fd7 100644
--- a/swh/deposit/tests/api/test_deposit_read_metadata.py
+++ b/swh/deposit/tests/api/test_deposit_read_metadata.py
@@ -1,211 +1,210 @@
# Copyright (C) 2017-2018 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-import json
from django.core.urlresolvers import reverse
from nose.tools import istest
from rest_framework import status
from rest_framework.test import APITestCase
from swh.deposit.models import Deposit
from swh.deposit.config import PRIVATE_GET_DEPOSIT_METADATA
from swh.deposit.config import DEPOSIT_STATUS_LOAD_SUCCESS
from swh.deposit.config import DEPOSIT_STATUS_PARTIAL
from ...config import SWH_PERSON
from ..common import BasicTestCase, WithAuthTestCase, CommonCreationRoutine
class DepositReadMetadataTest(APITestCase, WithAuthTestCase, BasicTestCase,
CommonCreationRoutine):
"""Deposit access to read metadata information on deposit.
"""
@istest
def read_metadata(self):
"""Private metadata read api to existing deposit should return metadata
"""
deposit_id = self.create_deposit_partial()
url = reverse(PRIVATE_GET_DEPOSIT_METADATA,
args=[self.collection.name, deposit_id])
response = self.client.get(url)
self.assertEqual(response.status_code,
status.HTTP_200_OK)
self.assertEquals(response._headers['content-type'][1],
'application/json')
- data = json.loads(response.content.decode('utf-8'))
+ data = response.json()
expected_meta = {
'origin': {
'url': 'https://hal-test.archives-ouvertes.fr/' +
'some-external-id',
'type': 'deposit'
},
'origin_metadata': {
'metadata': {
'@xmlns': ['http://www.w3.org/2005/Atom'],
'author': ['some awesome author', 'another one', 'no one'],
'external_identifier': 'some-external-id',
'url': 'https://hal-test.archives-ouvertes.fr/' +
'some-external-id'
},
'provider': {
'provider_name': 'hal',
'provider_type': 'deposit_client',
'provider_url': 'https://hal-test.archives-ouvertes.fr/',
'metadata': {}
},
'tool': {
'tool_name': 'swh-deposit',
'tool_version': '0.0.1',
'tool_configuration': {
'sword_version': '2'
}
}
},
'revision': {
'synthetic': True,
'committer_date': None,
'message': 'hal: Deposit %s in collection hal' % deposit_id,
'author': SWH_PERSON,
'committer': SWH_PERSON,
'date': None,
'metadata': {
'@xmlns': ['http://www.w3.org/2005/Atom'],
'author': ['some awesome author', 'another one', 'no one'],
'external_identifier': 'some-external-id',
'url': 'https://hal-test.archives-ouvertes.fr/' +
'some-external-id'
},
'type': 'tar'
},
'branch_name': 'master',
}
self.assertEquals(data, expected_meta)
@istest
def read_metadata_revision_with_parent(self):
"""Private read metadata to a deposit (with parent) returns metadata
"""
swh_id = 'da78a9d4cf1d5d29873693fd496142e3a18c20fa'
swh_persistent_id = 'swh:1:rev:%s' % swh_id
deposit_id1 = self.create_deposit_with_status(
status=DEPOSIT_STATUS_LOAD_SUCCESS,
external_id='some-external-id',
swh_id=swh_persistent_id)
deposit_parent = Deposit.objects.get(pk=deposit_id1)
self.assertEquals(deposit_parent.swh_id, swh_persistent_id)
self.assertEquals(deposit_parent.external_id, 'some-external-id')
self.assertEquals(deposit_parent.status, DEPOSIT_STATUS_LOAD_SUCCESS)
deposit_id = self.create_deposit_partial(
external_id='some-external-id')
deposit = Deposit.objects.get(pk=deposit_id)
self.assertEquals(deposit.external_id, 'some-external-id')
self.assertEquals(deposit.swh_id, None)
self.assertEquals(deposit.parent, deposit_parent)
self.assertEquals(deposit.status, DEPOSIT_STATUS_PARTIAL)
url = reverse(PRIVATE_GET_DEPOSIT_METADATA,
args=[self.collection.name, deposit_id])
response = self.client.get(url)
self.assertEqual(response.status_code,
status.HTTP_200_OK)
self.assertEquals(response._headers['content-type'][1],
'application/json')
- data = json.loads(response.content.decode('utf-8'))
+ data = response.json()
expected_meta = {
'origin': {
'url': 'https://hal-test.archives-ouvertes.fr/' +
'some-external-id',
'type': 'deposit'
},
'origin_metadata': {
'metadata': {
'@xmlns': ['http://www.w3.org/2005/Atom'],
'author': ['some awesome author', 'another one', 'no one'],
'external_identifier': 'some-external-id',
'url': 'https://hal-test.archives-ouvertes.fr/' +
'some-external-id'
},
'provider': {
'provider_name': 'hal',
'provider_type': 'deposit_client',
'provider_url': 'https://hal-test.archives-ouvertes.fr/',
'metadata': {}
},
'tool': {
'tool_name': 'swh-deposit',
'tool_version': '0.0.1',
'tool_configuration': {
'sword_version': '2'
}
}
},
'revision': {
'synthetic': True,
'date': None,
'committer_date': None,
'author': SWH_PERSON,
'committer': SWH_PERSON,
'type': 'tar',
'message': 'hal: Deposit %s in collection hal' % deposit_id,
'metadata': {
'@xmlns': ['http://www.w3.org/2005/Atom'],
'author': ['some awesome author', 'another one', 'no one'],
'external_identifier': 'some-external-id',
'url': 'https://hal-test.archives-ouvertes.fr/' +
'some-external-id'
},
'parents': [swh_id]
},
'branch_name': 'master',
}
self.assertEqual(data, expected_meta)
@istest
def access_to_nonexisting_deposit_returns_404_response(self):
"""Read unknown collection should return a 404 response
"""
unknown_id = '999'
url = reverse(PRIVATE_GET_DEPOSIT_METADATA,
args=[self.collection.name, unknown_id])
response = self.client.get(url)
self.assertEqual(response.status_code,
status.HTTP_404_NOT_FOUND)
self.assertIn('Deposit with id %s does not exist' % unknown_id,
response.content.decode('utf-8'))
@istest
def access_to_nonexisting_collection_returns_404_response(self):
"""Read unknown deposit should return a 404 response
"""
collection_name = 'non-existing'
deposit_id = self.create_deposit_partial()
url = reverse(PRIVATE_GET_DEPOSIT_METADATA,
args=[collection_name, deposit_id])
response = self.client.get(url)
self.assertEqual(response.status_code,
status.HTTP_404_NOT_FOUND)
self.assertIn('Unknown collection name %s' % collection_name,
response.content.decode('utf-8'),)
diff --git a/version.txt b/version.txt
index 1b9fc6b7..a2197500 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-v0.0.60-0-gfc4a329
\ No newline at end of file
+v0.0.61-0-gc0ebcaa
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Aug 18, 7:49 PM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3250609
Attached To
rDDEP Push deposit
Event Timeline
Log In to Comment