summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-04-23 20:52:56 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-04-23 20:52:56 -0700
commit176c76597dd42705cf3aaf307b831cb5f979d9bb (patch)
tree1751b416e44e2af7c7aa750b7974d895054b69f8
parent7b54c0ddea077d1d35c9a7945b73923dbc3288ec (diff)
downloadfatcat-176c76597dd42705cf3aaf307b831cb5f979d9bb.tar.gz
fatcat-176c76597dd42705cf3aaf307b831cb5f979d9bb.zip
improve test coverage
-rw-r--r--fatcat/api_client.py11
-rw-r--r--fatcat/routes.py24
-rw-r--r--tests/routes.py30
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/<int:ident>', 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/<int:ident>', 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/<int:ident>', 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/<int:ident>', 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/<int:ident>', 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/<int:ident>', 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/<username>', 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/<username>/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