From 176c76597dd42705cf3aaf307b831cb5f979d9bb Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 23 Apr 2018 20:52:56 -0700 Subject: improve test coverage --- fatcat/api_client.py | 11 ++++------- fatcat/routes.py | 24 ------------------------ tests/routes.py | 30 +++++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/fatcat/api_client.py b/fatcat/api_client.py index e371b727..0c9336ee 100644 --- a/fatcat/api_client.py +++ b/fatcat/api_client.py @@ -12,13 +12,10 @@ class FatCatApiClient: def get(self, path): return self.session.get(self.host_url + path) - def post(self, path, data=None, headers=None): - hdrs = {"content-type": "application/json"} - if headers: - hdrs.update(headers) - #if type(data) == dict: - # data = json.dumps(data, indent=None).encode('utf-8') - return self.session.post(self.host_url + path, json=data, headers=hdrs) + def post(self, path, data=None): + headers = {"content-type": "application/json"} + return self.session.post(self.host_url + path, json=data, + headers=headers) def import_crossref_file(self, json_file): eg = self.new_editgroup() diff --git a/fatcat/routes.py b/fatcat/routes.py index b1568833..ba12043d 100644 --- a/fatcat/routes.py +++ b/fatcat/routes.py @@ -21,18 +21,12 @@ def work_random(): @app.route('/work/', methods=['GET']) def work_view(ident): rv = api.api_work_get(ident) - if rv.status_code != 200: - # TODO: better wrapping for all entities - return abort(rv.status_code) entity = json.loads(rv.data.decode('utf-8')) return render_template('work_view.html', work=entity) @app.route('/release/', methods=['GET']) def release_view(ident): rv = api.api_release_get(ident) - if rv.status_code != 200: - # TODO: better wrapping for all entities - return abort(rv.status_code) entity = json.loads(rv.data.decode('utf-8')) return render_template('release_view.html', release=entity) @@ -45,36 +39,24 @@ def release_random(): @app.route('/creator/', methods=['GET']) def creator_view(ident): rv = api.api_creator_get(ident) - if rv.status_code != 200: - # TODO: better wrapping for all entities - return abort(rv.status_code) entity = json.loads(rv.data.decode('utf-8')) return render_template('creator_view.html', creator=entity) @app.route('/container/', methods=['GET']) def container_view(ident): rv = api.api_container_get(ident) - if rv.status_code != 200: - # TODO: better wrapping for all entities - return abort(rv.status_code) entity = json.loads(rv.data.decode('utf-8')) return render_template('container_view.html', container=entity) @app.route('/file/', methods=['GET']) def file_view(ident): rv = api.api_file_get(ident) - if rv.status_code != 200: - # TODO: better wrapping for all entities - return abort(rv.status_code) entity = json.loads(rv.data.decode('utf-8')) return render_template('file_view.html', file=entity) @app.route('/editgroup/', methods=['GET']) def editgroup_view(ident): rv = api.api_editgroup_get(ident) - if rv.status_code != 200: - # TODO: better wrapping for all entities - return abort(rv.status_code) entity = json.loads(rv.data.decode('utf-8')) return render_template('editgroup_view.html', editgroup=entity) @@ -86,18 +68,12 @@ def editgroup_current(): @app.route('/editor/', methods=['GET']) def editor_view(username): rv = api.api_editor_get(username) - if rv.status_code != 200: - # TODO: better wrapping for all entities - return abort(rv.status_code) entity = json.loads(rv.data.decode('utf-8')) return render_template('editor_view.html', editor=entity) @app.route('/editor//changelog', methods=['GET']) def editor_changelog(username): rv = api.api_editor_get(username) - if rv.status_code != 200: - # TODO: better wrapping for all entities - return abort(rv.status_code) editor = json.loads(rv.data.decode('utf-8')) rv = api.api_editor_changelog(username) changelog_entries = json.loads(rv.data.decode('utf-8')) diff --git a/tests/routes.py b/tests/routes.py index e389a55f..d74412b6 100644 --- a/tests/routes.py +++ b/tests/routes.py @@ -26,15 +26,39 @@ def test_all_views(rich_app): rv = app.get('/{}/1'.format(route)) assert rv.status_code == 200 - rv = app.get('/v0/work/random') - rv = app.get(rv.location) - assert rv.status_code == 200 + rv = app.get('/{}/999999999999'.format(route)) + assert rv.status_code == 404 + + rv = app.get('/work/random') + rv = app.get(rv.location) + assert rv.status_code == 200 + + rv = app.get('/work/random') + assert rv.status_code == 302 + + rv = app.get('/work/create') + assert rv.status_code == 200 + + rv = app.get('/release/random') + assert rv.status_code == 302 rv = app.get('/editgroup/1') assert rv.status_code == 200 + rv = app.get('/editgroup/99999999') + assert rv.status_code == 404 + + rv = app.get('/editgroup/current') + assert rv.status_code == 302 + rv = app.get('/editor/admin') assert rv.status_code == 200 + rv = app.get('/editor/bizzaro') + assert rv.status_code == 404 + rv = app.get('/editor/admin/changelog') assert rv.status_code == 200 + + rv = app.get('/editor/bizarro/changelog') + assert rv.status_code == 404 -- cgit v1.2.3