# 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", "type": "All-Grain", "efficiency": "65", "name": "Awesome Lager", "notes": "Test", "volume": "5.5", "fermentables": [], "hops": [], "style": "", } ) put_doc( { "_id": "partial-yeast-recipe", "$type": "recipe", "efficiency": "75", "name": "Partial Beer", "type": "Extract", "notes": "Contains only required fields for yeast.", "volume": "3.5", "fermentables": [], "hops": [], "yeast": { "name": "US-05", "low_attenuation": "60", "high_attenuation": "72", }, "style": "", } ) put_doc( { "_id": "full-recipe", "$type": "recipe", "efficiency": "78", "type": "All-Grain", "name": "Awesome Beer", "notes": ( "This is a test beer that contains most possible fields." ), "volume": "2.5", "style": "1A", "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", }, "mash": { "name": "Single Infusion", "steps": [ { "name": "Infusion", "type": "Infusion", "temp": "152", "time": "60", "amount": "3.5", } ], }, } ) # Add a test style put_doc( { "$type": "style", "_id": "1A", "abv": {"high": "100", "low": "0"}, "appearance": "Good looking", "aroma": "Smelly", "fg": {"high": "1.2", "low": "1.0"}, "flavor": "Good tasting", "ibu": {"high": "100", "low": "0"}, "id": "1A", "impression": "Refreshing", "mouthfeel": "Good feeling", "name": "Test Style", "og": {"high": "1.2", "low": "1.0"}, "srm": {"high": "100", "low": "0"}, } ) 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 { "lager": { "efficiency": "72", "type": "All-Grain", "style": "", "fermentables": [ { "amount": "9.5", "color": "1.80", "name": "Pale Malt, 2-row (Rahr) (US)", "ppg": "37.00", "type": "Grain", }, { "amount": "1", "color": "0", "name": "Corn Sugar (Dextrose)", "ppg": "46.00", "type": "Sugar", }, ], "hops": [ { "alpha": "7.0", "amount": "1", "duration": "60", "name": "Cluster (US)", "use": "Boil", }, { "alpha": "2.8", "amount": "1", "duration": "10.00", "name": "Saaz (CZ)", "use": "Boil", }, { "alpha": "2.8", "amount": "1.0", "duration": "5", "name": "Saaz (CZ)", "use": "Dry-Hop", }, ], "name": "Lager", "notes": "Test simple dry-hopped lager w/ sugar", "volume": "5.50", "yeast": { "abv_tolerance": "15.00", "code": "WLP940", "flocculation": "Medium", "high_attenuation": "78.00", "lab": "White Labs", "low_attenuation": "70.00", "max_temperature": "55.00", "min_temperature": "50.00", "name": "Mexican Lager", "type": "Liquid", }, }, "sweetstout": { "efficiency": "72", "type": "All-Grain", "style": "", "fermentables": [ { "amount": "2.75", "color": "3", "name": "Pale Malt, 2-row (UK)", "ppg": "36.00", "type": "Grain", }, { "amount": "0.25", "color": "450", "name": "Chocolate Malt (UK)", "ppg": "34.00", "type": "Grain", }, { "amount": "0.5", "color": "0", "name": "Lactose", "ppg": "35.00", "type": "Non-fermentable", }, ], "hops": [ { "alpha": "5.0", "amount": "0.5", "duration": "60", "name": "East Kent Goldings (UK)", "use": "Boil", }, { "alpha": "5.0", "amount": "0.5", "duration": "30", "name": "East Kent Goldings (UK)", "use": "Boil", }, ], "name": "Sweet Stout", "notes": "Test stout w/ Lactose", "volume": "2.5", "yeast": { "abv_tolerance": "12.00", "code": "", "flocculation": "High", "high_attenuation": "77.00", "lab": "Danstar", "low_attenuation": "73.00", "max_temperature": "70.00", "min_temperature": "57.00", "name": "Nottingham", "type": "Dry", }, }, }