diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/fatcat_web/routes.py | 8 | ||||
-rw-r--r-- | python/tests/web_editor.py | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py index 41027710..e9741b6d 100644 --- a/python/fatcat_web/routes.py +++ b/python/fatcat_web/routes.py @@ -606,6 +606,14 @@ def editor_annotations(ident): return render_template('editor_annotations.html', editor=editor, annotations=annotations) +@app.route('/u/<string:username>', methods=['GET', 'HEAD']) +def editor_username_redirect(username): + try: + editor = api.lookup_editor(username=username) + except ApiException as ae: + abort(ae.status) + return redirect(f'/editor/{editor.editor_id}') + @app.route('/changelog', methods=['GET']) def changelog_view(): try: diff --git a/python/tests/web_editor.py b/python/tests/web_editor.py index 58b21ddf..0d0679bb 100644 --- a/python/tests/web_editor.py +++ b/python/tests/web_editor.py @@ -22,3 +22,11 @@ def test_change_username(app_admin): assert rv.status_code == 200 rv = app_admin.get('/auth/account') assert b'admin-tmp' not in rv.data + +def test_username_redirect(app_admin): + + rv = app_admin.get('/u/admin') + assert rv.status_code == 302 + + rv = app_admin.get('/u/bogus-not-registered') + assert rv.status_code == 404 |