aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/fatcat/routes.py44
-rw-r--r--python/tests/routes.py26
2 files changed, 66 insertions, 4 deletions
diff --git a/python/fatcat/routes.py b/python/fatcat/routes.py
index 47e5863e..f4c7c513 100644
--- a/python/fatcat/routes.py
+++ b/python/fatcat/routes.py
@@ -31,6 +31,17 @@ def container_create():
edit = api.create_container(params=params)
return redirect("/container/{}".format(edit.ident))
+@app.route('/container/lookup', methods=['GET'])
+def container_lookup():
+ issnl = request.args.get('issnl')
+ if issnl is None:
+ abort(400)
+ try:
+ resp = api.lookup_container(issnl)
+ except ApiException as ae:
+ abort(ae.status)
+ return redirect('/container/{}'.format(resp.ident))
+
@app.route('/creator/<uuid:ident>', methods=['GET'])
def creator_view(ident):
try:
@@ -40,6 +51,17 @@ def creator_view(ident):
abort(ae.status)
return render_template('creator_view.html', creator=entity, releases=releases)
+@app.route('/creator/lookup', methods=['GET'])
+def creator_lookup():
+ orcid = request.args.get('orcid')
+ if orcid is None:
+ abort(400)
+ try:
+ resp = api.lookup_creator(orcid)
+ except ApiException as ae:
+ abort(ae.status)
+ return redirect('/creator/{}'.format(resp.ident))
+
@app.route('/file/<uuid:ident>', methods=['GET'])
def file_view(ident):
try:
@@ -48,6 +70,17 @@ def file_view(ident):
abort(ae.status)
return render_template('file_view.html', file=entity)
+@app.route('/file/lookup', methods=['GET'])
+def file_lookup():
+ sha1 = request.args.get('sha1')
+ if sha1 is None:
+ abort(400)
+ try:
+ resp = api.lookup_file(sha1)
+ except ApiException as ae:
+ abort(ae.status)
+ return redirect('/file/{}'.format(resp.ident))
+
@app.route('/release/<uuid:ident>', methods=['GET'])
def release_view(ident):
try:
@@ -59,6 +92,17 @@ def release_view(ident):
authors = sorted(authors, key=lambda c: c.index)
return render_template('release_view.html', release=entity, authors=authors, files=files)
+@app.route('/release/lookup', methods=['GET'])
+def release_lookup():
+ doi = request.args.get('doi')
+ if doi is None:
+ abort(400)
+ try:
+ resp = api.lookup_release(doi)
+ except ApiException as ae:
+ abort(ae.status)
+ return redirect('/release/{}'.format(resp.ident))
+
#@app.route('/release/<uuid:ident>/changelog', methods=['GET'])
#def release_changelog(ident):
# try:
diff --git a/python/tests/routes.py b/python/tests/routes.py
index d0af67c9..b2cfd058 100644
--- a/python/tests/routes.py
+++ b/python/tests/routes.py
@@ -24,22 +24,40 @@ def test_all_views(app):
rv = app.get('/{}/f1f046a3-45c9-ffff-ffff-ffffffffffff'.format(route))
assert rv.status_code == 404
- rv = app.get('/container/00000000-0000-0000-1111-000000000002'.format(route))
+ rv = app.get('/container/00000000-0000-0000-1111-000000000002')
assert rv.status_code == 200
rv = app.get('/container/create')
assert rv.status_code == 200
- rv = app.get('/creator/00000000-0000-0000-2222-000000000002'.format(route))
+ rv = app.get('/container/lookup')
+ assert rv.status_code == 400
+
+ rv = app.get('/container/lookup?issnl=9999-9999')
+ assert rv.status_code == 404
+
+ rv = app.get('/container/lookup?issnl=1234-5678')
+ assert rv.status_code == 302
+
+ rv = app.get('/creator/00000000-0000-0000-2222-000000000002')
assert rv.status_code == 200
- rv = app.get('/file/00000000-0000-0000-3333-000000000002'.format(route))
+ rv = app.get('/creator/lookup?orcid=0000-0003-2088-7465')
+ assert rv.status_code == 302
+
+ rv = app.get('/file/00000000-0000-0000-3333-000000000002')
+ assert rv.status_code == 200
+
+ rv = app.get('/file/lookup?sha1=7d97e98f8af710c7e7fe703abc8f639e0ee507c4')
+ assert rv.status_code == 302
+
+ rv = app.get('/release/00000000-0000-0000-4444-000000000002')
assert rv.status_code == 200
rv = app.get('/release/00000000-0000-0000-4444-000000000002'.format(route))
assert rv.status_code == 200
- rv = app.get('/work/00000000-0000-0000-5555-000000000002'.format(route))
+ rv = app.get('/work/00000000-0000-0000-5555-000000000002')
assert rv.status_code == 200
rv = app.get('/work/create')