# 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) @pytest.fixture def sample_recipes(): """These sample recipes are useful for testing filters.""" return { 'blonde-ale': { 'efficiency': '68.00', 'fermentables': [ { 'amount': '8.50', 'color': '1.80', 'name': 'Pale Malt, 2-row (Rahr) (US)', 'ppg': '37.00', 'type': 'Grain' }, { 'amount': '0.50', 'color': '10.00', 'name': 'Munich Malt 10L (Briess) (US)', 'ppg': '35.00', 'type': 'Grain' } ], 'hops': [ { 'alpha': '9.30', 'amount': '0.50', 'duration': '30.00', 'name': 'Cascade (US)', 'use': 'Boil' }, { 'alpha': '9.30', 'amount': '0.50', 'duration': '15.00', 'name': 'Cascade (US)', 'use': 'Boil' }, { 'alpha': '9.30', 'amount': '1.00', 'duration': '5.00', 'name': 'Cascade (US)', 'use': 'Boil' } ], 'name': 'Blonde Ale Base', 'notes': "This is a base recipe. It's okay on its own, but" 'better with other things, like fruits.', 'volume': '5.50', 'yeast': { 'abv_tolerance': '15.00', 'code': 'WLP090', 'flocculation': 'High', 'high_attenuation': '83.00', 'lab': 'White Labs', 'low_attenuation': '76.00', 'max_temperature': '68.00', 'min_temperature': '65.00', 'name': 'San Diego Super Yeast', 'type': 'Liquid' } } }