mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 19:39:43 +00:00
Add more complete tests for updates
This commit is contained in:
parent
8db04fc3aa
commit
7f94fabd6d
3 changed files with 121 additions and 76 deletions
|
|
@ -86,6 +86,7 @@
|
||||||
{#-
|
{#-
|
||||||
Yeast
|
Yeast
|
||||||
-#}
|
-#}
|
||||||
|
{% if yeast in recipe %}
|
||||||
<div class="row"><h2>Yeast</h2></div></div>
|
<div class="row"><h2>Yeast</h2></div></div>
|
||||||
<div class="row"><div class="col">
|
<div class="row"><div class="col">
|
||||||
<table class="table table-hover table-sm">
|
<table class="table table-hover table-sm">
|
||||||
|
|
@ -104,13 +105,22 @@
|
||||||
<td>{{ recipe.yeast.name }}</td>
|
<td>{{ recipe.yeast.name }}</td>
|
||||||
<td>{{ recipe.yeast.lab }}</td>
|
<td>{{ recipe.yeast.lab }}</td>
|
||||||
<td>{{ recipe.yeast.code }}</td>
|
<td>{{ recipe.yeast.code }}</td>
|
||||||
<td>{{ recipe.yeast.low_attenuation|int }}% - {{ recipe.yeast.high_attenuation|int }}%</td>
|
<td>
|
||||||
<td>{{ recipe.yeast.min_temperature|int }}°F - {{ recipe.yeast.max_temperature|int }}°F</td>
|
{% if 'low_attenuation' in recipe.yeast %}{{ recipe.yeast.low_attenuation|int }}%{% endif %}
|
||||||
<td>{{ recipe.yeast.flocculation }}</td>
|
{% if 'low_attenuation' in recipe.yeast and 'high_attenuation' in recipe.yeast %} - {% endif %}
|
||||||
<td>{{ recipe.yeast.abv_tolerance|int }}%</td>
|
{% 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>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div></div>
|
</div></div>
|
||||||
|
{% endif %}
|
||||||
{#-
|
{#-
|
||||||
Buttons to do things
|
Buttons to do things
|
||||||
-#}
|
-#}
|
||||||
|
|
|
||||||
|
|
@ -37,13 +37,80 @@ def app():
|
||||||
# Add a test doc
|
# Add a test doc
|
||||||
put_doc({'data': 'test', '_id': 'foobar'})
|
put_doc({'data': 'test', '_id': 'foobar'})
|
||||||
|
|
||||||
# Add a test recipe
|
# Add a couple test recipe
|
||||||
put_doc({
|
put_doc({
|
||||||
'_id': 'awesome-lager',
|
'_id': 'awesome-lager',
|
||||||
'efficiency': '65',
|
'efficiency': '65',
|
||||||
'name': 'Awesome Lager',
|
'name': 'Awesome Lager',
|
||||||
'notes': 'Test',
|
'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
|
yield app
|
||||||
|
|
|
||||||
|
|
@ -45,81 +45,49 @@ def test_create(client, app):
|
||||||
|
|
||||||
def test_update(client, app):
|
def test_update(client, app):
|
||||||
"""Test success in updating a recipe document."""
|
"""Test success in updating a recipe document."""
|
||||||
with app.app_context():
|
# Test GET on a bare minimum recipe
|
||||||
doc = put_doc({
|
response = client.get('/recipes/update/awesome-lager')
|
||||||
'_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')
|
|
||||||
assert response.status_code == 200
|
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
|
# Test GET on a more complete recipe
|
||||||
data = {
|
response = client.get('/recipes/update/full-recipe')
|
||||||
'name': 'New Name',
|
assert response.status_code == 200
|
||||||
'efficiency': '60',
|
test_items = [
|
||||||
'volume': '5.5',
|
b'Awesome Beer',
|
||||||
'notes': 'This is a test'
|
b'2row',
|
||||||
}
|
b'Dextrose',
|
||||||
response = client.post('/recipes/update/test-update',
|
b'Nugget (US)',
|
||||||
query_string={'rev': doc['_rev']}, data=data)
|
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
|
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
|
# Test response without valid/conflicted rev
|
||||||
response = client.post('/recipes/update/test-update',
|
response = client.post('/recipes/update/awesome-lager',
|
||||||
query_string={'rev': ''}, data=data)
|
query_string={'rev': ''}, data=doc)
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
with client.session_transaction() as session:
|
with client.session_transaction() as session:
|
||||||
flash_message = dict(session['_flashes']).pop('danger', None)
|
flash_message = dict(session['_flashes']).pop('danger', None)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue