1
0
Fork 0
mirror of https://github.com/shouptech/humulus.git synced 2026-02-03 15:09:42 +00:00

Abort w/ 400 is view is not found

This commit is contained in:
Emma 2019-07-07 08:28:22 -06:00
parent a58b93285c
commit b5cf298b49
No known key found for this signature in database
GPG key ID: 68434BFE85360755
2 changed files with 12 additions and 2 deletions

View file

@ -17,7 +17,8 @@
import json
from decimal import Decimal
from flask import (Blueprint, flash, redirect, render_template, jsonify,
import requests
from flask import (abort, Blueprint, flash, redirect, render_template, jsonify,
request, url_for)
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileRequired
@ -262,11 +263,16 @@ def index():
['true', 'yes']
)
sort_by = request.args.get('sort_by', default='name', type=str)
view = get_view('_design/recipes', 'by-{}'.format(sort_by))
try:
rows = view(include_docs=True, descending=descending)['rows']
except requests.exceptions.HTTPError:
abort(400)
return render_template(
'recipes/index.html',
rows=view(include_docs=True, descending=descending)['rows'],
rows=rows,
descending=descending,
sort_by=sort_by
)

View file

@ -22,6 +22,10 @@ from humulus.recipes import FermentableForm, HopForm, RecipeForm, YeastForm
def test_index(client):
"""Test success in retrieving index."""
# Test for bad request
response = client.get('/recipes/?sort_by=foobar')
assert response.status_code == 400
# Verify defaults
response = client.get('/recipes/')
assert response.status_code == 200