diff --git a/apps/iiif/annotations/tests.py b/apps/iiif/annotations/tests.py index 0b7ebfe6e..4e06fad0e 100644 --- a/apps/iiif/annotations/tests.py +++ b/apps/iiif/annotations/tests.py @@ -1,19 +1,11 @@ from django.test import TestCase from django.conf import settings -from django.core.checks import Warning +import warnings from .views import AnnotationListCreate from rest_framework.test import APIRequestFactory from rest_framework.test import APIClient from rest_framework.test import APITestCase -import requests import json -from os import killpg, path, setsid -import signal -import subprocess -import logging - -logger = logging.getLogger(__name__) - class AnnotationTests(APITestCase): factory = APIRequestFactory() @@ -71,24 +63,4 @@ def test_get_annotations_for_page(self): 'readux/annotations/MSS_Vat.lat.3225/p0005', format='json') response = view(request) response.render() - assert response.status_code == 200 - - def test_validate_iiif(self): - iiif_validator = path.abspath(path.join( - str(settings.ROOT_DIR.path()), - 'presentation-validator', - 'iiif-presentation-validator.py') - ) - if (not path.isfile(iiif_validator)): - command = 'python presentation-validator/iiif-presentation-validator.py' - process = subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - shell=True, preexec_fn=setsid - ) - killpg(process.pid, signal.SIGTERM) - else: - return Warning( - 'IIIF Presentation Validator not found.', - hint='Check README', - id='R001' - ) + assert response.status_code == 200 diff --git a/apps/iiif/canvases/models.py b/apps/iiif/canvases/models.py index 1e580c211..55c4029c7 100644 --- a/apps/iiif/canvases/models.py +++ b/apps/iiif/canvases/models.py @@ -56,9 +56,8 @@ def social_media(self): return "%s/%s/full/600,/0/default.jpg" % (self.IIIF_IMAGE_SERVER_BASE, self.pid) @property - def startingpage(self): - if self.is_starting_page is True: - return "%s/iiif/%s/" % (settings.HOSTNAME, self.manifest.pid) + def uri(self): + return "%s/iiif/%s/" % (settings.HOSTNAME, self.manifest.pid) @property def thumbnail_crop_landscape(self): diff --git a/apps/iiif/canvases/views.py b/apps/iiif/canvases/views.py index a6ae8f7d7..299166da4 100644 --- a/apps/iiif/canvases/views.py +++ b/apps/iiif/canvases/views.py @@ -36,6 +36,7 @@ def post(self, request, *args, **kwargs): annotation.save() return JsonResponse(oa_annotation, safe=False) +# TODO It should be okay to remove this. class StartingCanvas(View): def get_queryset(self): return Canvas.objects.filter(is_starting_page=True) diff --git a/apps/iiif/manifests/models.py b/apps/iiif/manifests/models.py index 2bb6816df..8ebbeb64f 100644 --- a/apps/iiif/manifests/models.py +++ b/apps/iiif/manifests/models.py @@ -38,6 +38,11 @@ def publisher_bib(self): @property def baseurl(self): return "%s/iiif/v2/%s" % (settings.HOSTNAME, self.pid) + + @property + def start_canvas(self): + first = self.canvas_set.all().exclude(is_starting_page=False).first() + return first.identifier if first else self.canvas_set.all().first().identifier # def autocomplete_label(self): # return self.label diff --git a/apps/iiif/manifests/tests.py b/apps/iiif/manifests/tests.py index 7ce503c2d..0d87e1a72 100644 --- a/apps/iiif/manifests/tests.py +++ b/apps/iiif/manifests/tests.py @@ -1,3 +1,27 @@ from django.test import TestCase +from rest_framework.test import APIRequestFactory +from rest_framework.test import APIClient +from rest_framework.test import APITestCase +from .views import ManifestDetail +from .models import Manifest +from iiif_prezi.loader import ManifestReader +import json +import logging -# Create your tests here. +logger = logging.getLogger(__name__) + +class AnnotationTests(APITestCase): + factory = APIRequestFactory() + fixtures = ['kollections.json', 'manifests.json', 'canvases.json', 'annotations.json'] + + def test_validate_iiif(self): + view = ManifestDetail.as_view() + manifest = Manifest.objects.all().first() + manifest_uri = '/'.join(['/iiif', 'v2', manifest.pid, 'manifest']) + response = self.client.get(manifest_uri) + reader = ManifestReader(response.content, version='2.1') + try: + mf = reader.read() + assert mf.toJSON() + except Exception as error: + raise Exception(error) diff --git a/apps/iiif/serializers/annotation.py b/apps/iiif/serializers/annotation.py index 2fd196a1a..e85786206 100644 --- a/apps/iiif/serializers/annotation.py +++ b/apps/iiif/serializers/annotation.py @@ -30,7 +30,7 @@ def start_object(self, obj): def get_dump_object(self, obj): if ((self.version == 'v2') or (self.version is None)): data = { - "@context": "https://iiif.io/api/presentation/2/context.json", + "@context": "http://iiif.io/api/presentation/2/context.json", "@id": str(obj.pk), "@type": "oa:Annotation", "motivation": obj.motivation, diff --git a/apps/iiif/serializers/annotation_list.py b/apps/iiif/serializers/annotation_list.py index 14fd86213..7f63a0aa6 100644 --- a/apps/iiif/serializers/annotation_list.py +++ b/apps/iiif/serializers/annotation_list.py @@ -32,7 +32,7 @@ def start_object(self, obj): def get_dump_object(self, obj): if ((self.version == 'v2') or (self.version is None)): data = { - "@context": "https://iiif.io/api/presentation/2/context.json", + "@context": "http://iiif.io/api/presentation/2/context.json", "@id": "%s/iiif/%s/list/%s" % (settings.HOSTNAME, obj.manifest.pid, obj.pid), "@type": "sc:AnnotationList", "resources": json.loads(serialize('annotation', obj.annotation_set.all().distinct('order'), islist=True)) diff --git a/apps/iiif/serializers/canvas.py b/apps/iiif/serializers/canvas.py index bea9cfb63..8a05d7b8a 100644 --- a/apps/iiif/serializers/canvas.py +++ b/apps/iiif/serializers/canvas.py @@ -5,7 +5,7 @@ V2 { // Metadata about this canvas - "@context": "https://iiif.io/api/presentation/2/context.json", + "@context": "http://iiif.io/api/presentation/2/context.json", "@id": "https://example.org/iiif/book1/canvas/p1", "@type": "sc:Canvas", "label": "p. 1", @@ -80,9 +80,10 @@ def start_object(self, obj): super().start_object(obj) def get_dump_object(self, obj): + obj.label = str(obj.position) if ((self.version == 'v2') or (self.version is None)): data = { - "@context": "https://iiif.io/api/presentation/2/context.json", + "@context": "http://iiif.io/api/presentation/2/context.json", "@id": obj.identifier, "@type": "sc:Canvas", "label": obj.label, @@ -90,7 +91,7 @@ def get_dump_object(self, obj): "width": obj.width, "images": [ { - "@context": "https://iiif.io/api/presentation/2/context.json", + "@context": "http://iiif.io/api/presentation/2/context.json", "@id": "%s" % (obj.anno_id), "@type": "oa:Annotation", "motivation": "sc:painting", diff --git a/apps/iiif/serializers/kollection.py b/apps/iiif/serializers/kollection.py index b25aaac3c..10ca53c06 100644 --- a/apps/iiif/serializers/kollection.py +++ b/apps/iiif/serializers/kollection.py @@ -31,7 +31,7 @@ def start_object(self, obj): def get_dump_object(self, obj): if ((self.version == 'v2') or (self.version is None)): data = { - "@context": "https://iiif.io/api/presentation/2/context.json", + "@context": "http://iiif.io/api/presentation/2/context.json", "@id": "https://readux.ecds.emory.edu/iiif/v2/%s/collection" % (obj.pid), "@type": "sc:Collection", "label": obj.label, diff --git a/apps/iiif/serializers/manifest.py b/apps/iiif/serializers/manifest.py index 05dedcc46..c75a1af3f 100644 --- a/apps/iiif/serializers/manifest.py +++ b/apps/iiif/serializers/manifest.py @@ -7,7 +7,7 @@ V2 { // Metadata about this canvas - "@context": "https://iiif.io/api/presentation/2/context.json", + "@context": "http://iiif.io/api/presentation/2/context.json", "@id": 'https://example.org/iiif/%s/canvas/p1' % (obj.pid), "@type": "sc:Canvas", "label": "p. 1", @@ -77,7 +77,7 @@ def start_object(self, obj): def get_dump_object(self, obj): if ((self.version == 'v2') or (self.version is None)): data = { - "@context": "https://iiif.io/api/presentation/2/context.json", + "@context": "http://iiif.io/api/presentation/2/context.json", "@id": "%s/manifest" % (obj.baseurl), "@type": "sc:Manifest", "label": obj.label, @@ -104,7 +104,7 @@ def get_dump_object(self, obj): "label": "Current Page Order", "viewingDirection": obj.viewingDirection, "viewingHint": "paged", - "startCanvas": json.loads(serialize('startingcanvas', obj.canvas_set.all().exclude(is_starting_page=False), islist=True)), + "startCanvas": obj.start_canvas, "canvases": json.loads(serialize('canvas', obj.canvas_set.all(), islist=True)) } ] diff --git a/apps/iiif/serializers/startingcanvas.py b/apps/iiif/serializers/startingcanvas.py index 78cade374..db0c644fa 100644 --- a/apps/iiif/serializers/startingcanvas.py +++ b/apps/iiif/serializers/startingcanvas.py @@ -5,7 +5,7 @@ V2 { // Metadata about this canvas - "@context": "https://iiif.io/api/presentation/2/context.json", + "@context": "http://iiif.io/api/presentation/2/context.json", "@id": "https://example.org/iiif/book1/canvas/p1", "@type": "sc:Canvas", "label": "p. 1", diff --git a/requirements/local.txt b/requirements/local.txt index 2fb8f0c41..2cf15f353 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -11,6 +11,7 @@ mypy==0.641 # https://github.com/python/mypy pytest==3.9.3 # https://github.com/pytest-dev/pytest pytest-sugar==0.9.1 # https://github.com/Frozenball/pytest-sugar requests +iiif-prezi # https://github.com/iiif-prezi/iiif-prezi # Code quality # ------------------------------------------------------------------------------