{% block alert %} {% for category, message in get_flashed_messages(with_categories=true) %} @@ -54,7 +54,6 @@ limitations under the License. - diff --git a/src/humulus/templates/_macros.html b/src/humulus/templates/_macros.html index c64024c..ce38f32 100644 --- a/src/humulus/templates/_macros.html +++ b/src/humulus/templates/_macros.html @@ -13,13 +13,13 @@ See the License for the specific language governing permissions and limitations under the License. -#} -{% macro render_field_with_errors(field) %} +{% macro render_field_with_errors(field, size='') %}
- {{ field.label }} {{ field(class_='form-control', **kwargs)|safe }} + {{ field.label }} {{ field(class_='form-control ' + size, **kwargs)|safe }} {% if field.errors %} {% for error in field.errors %}
- +
{% endfor %} {% endif %} diff --git a/src/humulus/templates/recipes/create.html b/src/humulus/templates/recipes/create.html index 0de8edf..0f4c764 100644 --- a/src/humulus/templates/recipes/create.html +++ b/src/humulus/templates/recipes/create.html @@ -20,14 +20,165 @@ limitations under the License. {% block body %}

Create a new recipe

-
-
- {{ form.hidden_tag() }} - {{ render_field_with_errors(form.name) }} - {{ render_field_with_errors(form.efficiency) }} - {{ render_field_with_errors(form.volume) }} - {{ render_field_with_errors(form.notes) }} - -
-
+
+ {{ form.hidden_tag() }} +
+
{{ render_field_with_errors(form.name) }}
+
{{ render_field_with_errors(form.efficiency) }}
+
{{ render_field_with_errors(form.volume) }}
+
+ +
+

Fermentables

+
+
+ {% for fermentable in form.fermentables %} +
+
+
+ {{ render_field_with_errors(fermentable.form.name, 'form-control-sm') }} +
+
+
+
{{ render_field_with_errors(fermentable.form.type, 'form-control-sm') }}
+
{{ render_field_with_errors(fermentable.form.amount, 'form-control-sm') }}
+
{{ render_field_with_errors(fermentable.form.ppg, 'form-control-sm') }}
+
{{ render_field_with_errors(fermentable.form.color, 'form-control-sm') }}
+
+
+
+ +
+
+
+ {% endfor %} +
+
+
+ +
+
+
+
{{ render_field_with_errors(form.notes) }}
+
+
+
+
+
+ + {% endblock %} diff --git a/tests/test_recipes.py b/tests/test_recipes.py index c334ae4..f0ae8c5 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -12,10 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +from decimal import Decimal + from humulus.couch import get_db +from humulus.recipes import FermentableForm, RecipeForm def test_create(client, app): + """Test success in creating a recipe document.""" # Test GET response = client.get('/recipes/create') assert response.status_code == 200 @@ -40,6 +44,7 @@ def test_create(client, app): def test_info(client): + """Test success in retrieving a recipe document.""" # Validate 404 response = client.get('/recipes/info/thisdoesnotexist') assert response.status_code == 404 @@ -48,3 +53,40 @@ def test_info(client): response = client.get('/recipes/info/awesome-lager') assert response.status_code == 200 assert b'Awesome Lager' in response.data + + +def test_recipe_form_doc(app): + """Test if a recipeform can be turned into a document. + + This test also tests that subforms can be turned into a document. Subforms + are not tested individually since they will never be used individually. + """ + with app.app_context(): + recipe = RecipeForm() + + ferm = FermentableForm() + ferm.name.data = 'Test' + ferm.type.data = 'Grain' + ferm.amount.data = Decimal('5.5') + ferm.ppg.data = Decimal('37') + ferm.color.data = Decimal('1.8') + + recipe.name.data = 'Test' + recipe.efficiency.data = Decimal('65') + recipe.volume.data = Decimal('5.5') + recipe.notes.data = 'This is a test' + recipe.fermentables = [ferm] + + assert recipe.doc == { + 'name': 'Test', + 'efficiency': '65', + 'volume': '5.5', + 'notes': 'This is a test', + 'fermentables': [{ + 'name': 'Test', + 'type': 'Grain', + 'amount': '5.5', + 'ppg': '37', + 'color': '1.8', + }], + }