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

Add more complete tests for updates

This commit is contained in:
Emma 2019-06-25 15:36:19 -06:00
parent 8db04fc3aa
commit 7f94fabd6d
3 changed files with 121 additions and 76 deletions

View file

@ -86,6 +86,7 @@
{#-
Yeast
-#}
{% if yeast in recipe %}
<div class="row"><h2>Yeast</h2></div></div>
<div class="row"><div class="col">
<table class="table table-hover table-sm">
@ -104,13 +105,22 @@
<td>{{ recipe.yeast.name }}</td>
<td>{{ recipe.yeast.lab }}</td>
<td>{{ recipe.yeast.code }}</td>
<td>{{ recipe.yeast.low_attenuation|int }}% - {{ recipe.yeast.high_attenuation|int }}%</td>
<td>{{ recipe.yeast.min_temperature|int }}°F - {{ recipe.yeast.max_temperature|int }}°F</td>
<td>{{ recipe.yeast.flocculation }}</td>
<td>{{ recipe.yeast.abv_tolerance|int }}%</td>
<td>
{% if 'low_attenuation' in recipe.yeast %}{{ recipe.yeast.low_attenuation|int }}%{% endif %}
{% if 'low_attenuation' in recipe.yeast and 'high_attenuation' in recipe.yeast %} - {% endif %}
{% if 'high_attenuation' in recipe.yeast %}{{ recipe.yeast.high_attenuation|int }}%{% endif %}
</td>
<td>
{% if 'min_temperature' in recipe.yeast %}{{ recipe.yeast.min_temperature|int }}°F{% endif %}
{% if 'min_temperature' in recipe.yeast and 'max_temperature' in recipe.yeast %} - {% endif %}
{% if 'max_temperature' in recipe.yeast %}{{ recipe.yeast.max_temperature|int }}°F{% endif %}
</td>
<td>{% if 'flocculation' in recipe.yeast %}{{ recipe.yeast.flocculation }}{% endif %}</td>
<td>{% if 'abv_tolerance' in recipe.yeast %}{{ recipe.yeast.abv_tolerance|int }}%{% endif %}</td>
</tr>
</table>
</div></div>
{% endif %}
{#-
Buttons to do things
-#}

View file

@ -37,13 +37,80 @@ def app():
# Add a test doc
put_doc({'data': 'test', '_id': 'foobar'})
# Add a test recipe
# Add a couple test recipe
put_doc({
'_id': 'awesome-lager',
'efficiency': '65',
'name': 'Awesome Lager',
'notes': 'Test',
'volume': '5.5'
'volume': '5.5',
'fermentables': [],
'hops': []
})
put_doc({
'_id': 'partial-yeast-recipe',
'efficiency': '75',
'name': 'Partial Beer',
'notes': 'Contains only required fields for yeast.',
'volume': '3.5',
'fermentables': [],
'hops': [],
'yeast': {
'name': 'US-05',
'low_attenuation': '60',
'high_attenuation': '72',
}
})
put_doc({
'_id': 'full-recipe',
'efficiency': '78',
'name': 'Awesome Beer',
'notes': 'This is a test beer that contains most possible fields.',
'volume': '2.5',
'fermentables': [
{
'name': '2row',
'type': 'Grain',
'amount': '5',
'ppg': '37',
'color': '2'
},
{
'name': 'Dextrose',
'type': 'Sugar',
'amount': '1',
'ppg': '46',
'color': '1'
}
],
'hops': [
{
'name': 'Nugget (US)',
'use': 'Boil',
'alpha': '12.5',
'duration': '60',
'amount': '1'
},
{
'name': 'CTZ (US)',
'use': 'Dry-Hop',
'alpha': '16',
'duration': '5',
'amount': '0.5'
}
],
'yeast': {
'name': 'Northern California Ale',
'type': 'Liquid',
'lab': 'Inland Island',
'code': 'INIS-001',
'flocculation': 'Medium',
'low_attenuation': '73',
'high_attenuation': '77',
'min_temperature': '60',
'max_temperature': '72',
'abv_tolerance': '10'
}
})
yield app

View file

@ -45,81 +45,49 @@ def test_create(client, app):
def test_update(client, app):
"""Test success in updating a recipe document."""
with app.app_context():
doc = put_doc({
'_id': 'test-update',
'name': 'Test Update',
'efficiency': '60',
'volume': '5.5',
'notes': 'This is a test',
'fermentables': [],
'hops': []
})
# Test GET
response = client.get('/recipes/update/test-update')
# Test GET on a bare minimum recipe
response = client.get('/recipes/update/awesome-lager')
assert response.status_code == 200
assert b'Test Update' in response.data
assert b'Awesome Lager' in response.data
# Make a change to the doc
data = {
'name': 'New Name',
'efficiency': '60',
'volume': '5.5',
'notes': 'This is a test'
}
response = client.post('/recipes/update/test-update',
query_string={'rev': doc['_rev']}, data=data)
# Test GET on a more complete recipe
response = client.get('/recipes/update/full-recipe')
assert response.status_code == 200
test_items = [
b'Awesome Beer',
b'2row',
b'Dextrose',
b'Nugget (US)',
b'CTZ (US)',
b'Northern California Ale'
]
for item in test_items:
assert item in response.data
# Test GET on a recipe missing most yeast fields
response = client.get('/recipes/update/partial-yeast-recipe')
assert response.status_code == 200
test_items = [
b'Partial Beer',
b'US-05'
]
for item in test_items:
assert item in response.data
# Get a doc, make an update, and test a POST
id = 'awesome-lager'
with app.app_context():
doc = get_doc(id)
# Remove unneeded fields
doc.pop('_id')
rev = doc.pop('_rev')
response = client.post('/recipes/update/awesome-lager',
query_string={'rev': rev}, data=doc)
assert response.status_code == 302
with client.session_transaction() as session:
flash_message = dict(session['_flashes']).pop('danger', None)
assert flash_message is None
with app.app_context():
updated = get_doc('test-update')
assert updated['name'] == 'New Name'
# Test form is filled correctly with ingredients
with app.app_context():
doc = put_doc({
'_id': 'test-update-1',
'name': 'Test Update With Ingredients',
'efficiency': '60',
'volume': '5.5',
'notes': 'This is a test',
'fermentables': [{
'name': '2-row',
'type': 'Grain',
'amount': '5',
'ppg': '37',
'color': '1.8'
}],
'hops': [{
'name': 'Nugget',
'use': 'Boil',
'alpha': '5.5',
'duration': '60',
'amount': '1'
}],
'yeast': {
'name': 'California Ale',
'low_attenuation': '70',
'high_attenuation': '80',
'type': 'Liquid',
'lab': 'Inland Island',
'code': 'INIS-001',
'flocculation': 'Medium',
'min_temperature': '60',
'max_temperature': '70',
'abv_tolerance': '15'
}
})
response = client.get('/recipes/update/test-update-1')
assert b'Test Update With Ingredients' in response.data
# Test response without valid/conflicted rev
response = client.post('/recipes/update/test-update',
query_string={'rev': ''}, data=data)
response = client.post('/recipes/update/awesome-lager',
query_string={'rev': ''}, data=doc)
assert response.status_code == 302
with client.session_transaction() as session:
flash_message = dict(session['_flashes']).pop('danger', None)