Skip to content

Commit

Permalink
Merge b90f0ac into b78f034
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorSheehan1 committed Apr 30, 2019
2 parents b78f034 + b90f0ac commit fad1e5d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ build
dist
htmlcov
iiif_prezi.egg-info
.python-version
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
sudo: false
dist: xenial
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
# commands to install dependencies
install:
- pip install coveralls pep8 pep257 testfixtures
Expand Down
10 changes: 6 additions & 4 deletions iiif_prezi/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,14 @@ def toJSON(self, top=False):
del d['context']
for e in self._required:
if e not in d:
# if the current object has an id, include it in the error message
id_msg = " with id '%s'" % self.id if self.id else ""
err_msg = "Resource type '%s'%s requires '%s' to be set" % (self._type, id_msg, e)

if e in self._structure_properties:
raise StructuralError(
"Resource type '%s' requires '%s' to be set" % (self._type, e), self)
raise StructuralError(err_msg, self)
else:
raise RequirementError(
"Resource type '%s' requires '%s' to be set" % (self._type, e), self)
raise RequirementError(err_msg, self)
debug = self._factory.debug_level
if debug.find("warn") > -1:
for e in self._warn:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_loader_fixures.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def test02_errors(self):
# self.assertRaises( DataError, error, 49 ) #FIXME/zimeon py2-py3 diff
self.assertRaises(PresentationError, error, 50) # was DataError
self.assertRaises(RequirementError, error, 51)
self.assertRaises(RequirementError, error, 52)

def test05_multipleContexts(self):
fh = open('tests/multiple_contexts_fixture.json')
Expand Down Expand Up @@ -188,3 +189,10 @@ def test07_every_value_its_list(self):
js = json.loads(data)
mr = ManifestReader(js)
doc = mr.read()

def test52_canvas_id_in_error_message(self):
# even though the label key exists in manifest 51, it must have a truthy value
# in this case it has a value of empty string ''
err_id = "http://iiif.io/api/presentation/2.0/example/fixtures/canvas/2/c2.json"
err_msg = "^Resource type 'sc:Canvas' with id '%s' requires 'label' to be set$" % err_id
self.assertRaisesRegexp(RequirementError, err_msg, error, 52)
54 changes: 54 additions & 0 deletions tests/testdata/2.0/example/errors/52/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"@context": "http://iiif.io/api/presentation/2/context.json",
"@id": "http://iiif.io/api/presentation/2.0/example/fixtures/1/manifest.json",
"@type": "sc:Manifest",
"label": "Test 1 Manifest: Minimum Required Fields",
"within": "http://iiif.io/api/presentation/2.0/example/fixtures/collection.json",
"sequences": [
{
"@type": "sc:Sequence",
"canvases": [
{
"@id": "http://iiif.io/api/presentation/2.0/example/fixtures/canvas/1/c1.json",
"@type": "sc:Canvas",
"label": "good label",
"height": 1800,
"width": 1200,
"images": [
{
"@type": "oa:Annotation",
"motivation": "sc:painting",
"resource": {
"@id": "http://iiif.io/api/presentation/2.0/example/fixtures/resources/page1-full.png",
"@type": "dctypes:Image",
"height": 1800,
"width": 1200
},
"on": "http://iiif.io/api/presentation/2.0/example/fixtures/canvas/1/c1.json"
}
]
},
{
"@id": "http://iiif.io/api/presentation/2.0/example/fixtures/canvas/2/c2.json",
"@type": "sc:Canvas",
"label": "",
"height": 1800,
"width": 1200,
"images": [
{
"@type": "oa:Annotation",
"motivation": "sc:painting",
"resource": {
"@id": "http://iiif.io/api/presentation/2.0/example/fixtures/resources/page2-full.png",
"@type": "dctypes:Image",
"height": 1800,
"width": 1200
},
"on": "http://iiif.io/api/presentation/2.0/example/fixtures/canvas/2/c2.json"
}
]
}
]
}
]
}

0 comments on commit fad1e5d

Please sign in to comment.