Skip to content

Commit

Permalink
Added test to validate the rendered manifest using iiif-prezi.py. A n…
Browse files Browse the repository at this point in the history
…umber of small changes were made to make the manifest valid.
  • Loading branch information
jayvarner committed Apr 15, 2019
1 parent 375811b commit 701b7dd
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 44 deletions.
32 changes: 2 additions & 30 deletions apps/iiif/annotations/tests.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions apps/iiif/canvases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions apps/iiif/canvases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions apps/iiif/manifests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion apps/iiif/manifests/tests.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion apps/iiif/serializers/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion apps/iiif/serializers/annotation_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 4 additions & 3 deletions apps/iiif/serializers/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -80,17 +80,18 @@ 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,
"height": obj.height,
"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",
Expand Down
2 changes: 1 addition & 1 deletion apps/iiif/serializers/kollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions apps/iiif/serializers/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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))
}
]
Expand Down
2 changes: 1 addition & 1 deletion apps/iiif/serializers/startingcanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 701b7dd

Please sign in to comment.