1
0
Fork 0
mirror of https://github.com/shouptech/humulus.git synced 2026-02-03 17:09:44 +00:00
humulus/tests/conftest.py
2019-06-28 21:29:09 -06:00

154 lines
4.2 KiB
Python

# Copyright 2019 Mike Shoup
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import uuid
import pytest
from humulus import create_app
from humulus.couch import build_couch, get_couch, put_doc
@pytest.fixture
def app():
dbname = 'test_{}'.format(str(uuid.uuid4()))
couchurl = os.environ.get('COUCH_URL', 'http://127.0.0.1:5984')
app = create_app({
'COUCH_URL': couchurl,
'COUCH_USERNAME': 'admin',
'COUCH_PASSWORD': 'password',
'COUCH_DATABASE': dbname,
'WTF_CSRF_ENABLED': False,
'SECRET_KEY': 'testing',
'HUMULUS_PASSWORD': 'password'
})
with app.app_context():
# Create the database
build_couch()
# Add a test doc
put_doc({'data': 'test', '_id': 'foobar'})
# Add a couple test recipe
put_doc({
'_id': 'awesome-lager',
'$type': 'recipe',
'efficiency': '65',
'name': 'Awesome Lager',
'notes': 'Test',
'volume': '5.5',
'fermentables': [],
'hops': []
})
put_doc({
'_id': 'partial-yeast-recipe',
'$type': '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',
'$type': '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
with app.app_context():
get_couch().delete_database(dbname)
@pytest.fixture
def runner(app):
return app.test_cli_runner()
@pytest.fixture
def client(app):
return app.test_client()
class AuthActions(object):
def __init__(self, client):
self._client = client
def login(self, password='password'):
return self._client.post(
'/login',
data={'password': password}
)
def logout(self):
return self._client.get('/logout')
@pytest.fixture
def auth(client):
return AuthActions(client)