Skip to content

Commit

Permalink
In fixity check REST API:
Browse files Browse the repository at this point in the history
* Format fixity response as JSON
* Indicate success or failure in response body rather than in status
  code
  • Loading branch information
Stefano Cossu committed Nov 3, 2018
1 parent 41e2c0b commit 54aa942
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 15 additions & 4 deletions lakesuperior/endpoints/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from flask import Blueprint, render_template
from flask import Blueprint, jsonify, render_template

from lakesuperior.api import admin as admin_api
from lakesuperior.exceptions import (
Expand Down Expand Up @@ -59,13 +59,24 @@ def fixity_check(uid):
Check the fixity of a resource.
"""
uid = '/' + uid.strip('/')

try:
admin_api.fixity_check(uid)
except ResourceNotExistsError as e:
return str(e), 404
except TombstoneError as e:
return str(e), 410
except ChecksumValidationError as e:
return str(e), 412

return f'Checksum for {uid} passed.', 200
check_pass = False
else:
check_pass = True


return (
jsonify({
'uid': uid,
'pass': check_pass,
}),
200,
{'content-type': 'application/json'}
)
12 changes: 10 additions & 2 deletions tests/2_endpoints/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ def test_fixity_check_ok(self):
self.client.put(
path, data=content, headers={'content-type': 'text/plain'})

assert self.client.get(fix_path).status_code == 200
rsp = self.client.get(fix_path)

assert rsp.status_code == 200
assert rsp.json['uid'] == f'/{uid}'
assert rsp.json['pass'] == True


def test_fixity_check_corrupt(self):
Expand All @@ -45,7 +49,11 @@ def test_fixity_check_corrupt(self):
with open(rsrc.local_path, 'wb') as fh:
fh.write(uuid4().bytes)

assert self.client.get(fix_path).status_code == 412
rsp = self.client.get(fix_path)

assert rsp.status_code == 200
assert rsp.json['uid'] == f'/{uid}'
assert rsp.json['pass'] == False


def test_fixity_check_missing(self):
Expand Down

0 comments on commit 54aa942

Please sign in to comment.