mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 16:09:44 +00:00
Abort w/ 400 is view is not found
This commit is contained in:
parent
a58b93285c
commit
b5cf298b49
2 changed files with 12 additions and 2 deletions
|
|
@ -17,7 +17,8 @@
|
||||||
import json
|
import json
|
||||||
from decimal import Decimal
|
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)
|
request, url_for)
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from flask_wtf.file import FileField, FileRequired
|
from flask_wtf.file import FileField, FileRequired
|
||||||
|
|
@ -262,11 +263,16 @@ def index():
|
||||||
['true', 'yes']
|
['true', 'yes']
|
||||||
)
|
)
|
||||||
sort_by = request.args.get('sort_by', default='name', type=str)
|
sort_by = request.args.get('sort_by', default='name', type=str)
|
||||||
|
|
||||||
view = get_view('_design/recipes', 'by-{}'.format(sort_by))
|
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(
|
return render_template(
|
||||||
'recipes/index.html',
|
'recipes/index.html',
|
||||||
rows=view(include_docs=True, descending=descending)['rows'],
|
rows=rows,
|
||||||
descending=descending,
|
descending=descending,
|
||||||
sort_by=sort_by
|
sort_by=sort_by
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@ from humulus.recipes import FermentableForm, HopForm, RecipeForm, YeastForm
|
||||||
|
|
||||||
def test_index(client):
|
def test_index(client):
|
||||||
"""Test success in retrieving index."""
|
"""Test success in retrieving index."""
|
||||||
|
# Test for bad request
|
||||||
|
response = client.get('/recipes/?sort_by=foobar')
|
||||||
|
assert response.status_code == 400
|
||||||
|
|
||||||
# Verify defaults
|
# Verify defaults
|
||||||
response = client.get('/recipes/')
|
response = client.get('/recipes/')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue