def test_fermentation_steps_copy_with_override(self): model.Recipe(name='Rocky Mountain River IPA', fermentation_steps=[ model.FermentationStep(step='PRIMARY', days=14, fahrenheit=65), model.FermentationStep(step='SECONDARY', days=90, fahrenheit=45) ]) model.commit() recipe = model.Recipe.query.first() recipe.duplicate({ 'fermentation_steps': [model.FermentationStep(step='PRIMARY', days=21, fahrenheit=75)] }) model.commit() assert model.Recipe.query.count() == 2 assert model.FermentationStep.query.count() == 3 r1, r2 = model.Recipe.get(1), model.Recipe.get(2) assert len(r1.fermentation_steps) == 2 assert len(r2.fermentation_steps) == 1 assert r2.fermentation_steps[0].step == 'PRIMARY' assert r2.fermentation_steps[0].days == 21 assert r2.fermentation_steps[0].fahrenheit == 75
def test_fermentation_steps_copy(self): model.Recipe(name='Rocky Mountain River IPA', fermentation_steps=[ model.FermentationStep(step='PRIMARY', days=14, fahrenheit=65), model.FermentationStep(step='SECONDARY', days=90, fahrenheit=45) ]) model.commit() recipe = model.Recipe.query.first() recipe.duplicate() model.commit() assert model.Recipe.query.count() == 2 assert model.FermentationStep.query.count() == 4 r1, r2 = model.Recipe.get(1), model.Recipe.get(2) assert len(r1.fermentation_steps) == len(r2.fermentation_steps) == 2 assert r1.fermentation_steps[0].step == r2.fermentation_steps[ 0].step == 'PRIMARY' assert r1.fermentation_steps[0].days == r2.fermentation_steps[ 0].days == 14 assert r1.fermentation_steps[0].fahrenheit == r2.fermentation_steps[ 0].fahrenheit == 65 assert r1.fermentation_steps[1].step == r2.fermentation_steps[ 1].step == 'SECONDARY' assert r1.fermentation_steps[1].days == r2.fermentation_steps[ 1].days == 90 assert r1.fermentation_steps[1].fahrenheit == r2.fermentation_steps[ 1].fahrenheit == 45
def test_next_fermentation_step(self): recipe = model.Recipe() recipe.fermentation_steps.append( model.FermentationStep(step='PRIMARY', days=7, fahrenheit=50)) assert recipe.next_fermentation_step == 'SECONDARY' recipe.fermentation_steps.append( model.FermentationStep(step='SECONDARY', days=14, fahrenheit=35)) assert recipe.next_fermentation_step == 'TERTIARY' recipe.fermentation_steps.append( model.FermentationStep(step='TERTIARY', days=31, fahrenheit=35)) assert recipe.next_fermentation_step is None
def test_draft_merge_fermentation_steps(self): model.Recipe(name='Rocky Mountain River IPA', fermentation_steps=[ model.FermentationStep(step='PRIMARY', days=14, fahrenheit=65), model.FermentationStep(step='SECONDARY', days=90, fahrenheit=45) ], state=u'PUBLISHED') model.commit() # Make a new draft of the recipe model.Recipe.query.first().draft() model.commit() assert model.Recipe.query.count() == 2 # Change the fermentation schedule of the draft draft = model.Recipe.query.filter( model.Recipe.state == 'DRAFT').first() draft.fermentation_steps = [ model.FermentationStep(step='PRIMARY', days=21, fahrenheit=75) ] model.commit() # Merge the draft back into its origin recipe. draft = model.Recipe.query.filter( model.Recipe.state == 'DRAFT').first() draft.publish() model.commit() # Make sure the remaining version is the (newly saved) draft assert model.Recipe.query.count() == 1 assert model.FermentationStep.query.count() == 1 published = model.Recipe.query.first() assert published.fermentation_steps[0].step == 'PRIMARY' assert published.fermentation_steps[0].days == 21 assert published.fermentation_steps[0].fahrenheit == 75
def test_fermentation_step(self): recipe = model.Recipe() recipe.fermentation_steps.extend([ model.FermentationStep(step='PRIMARY', days=7, fahrenheit=50), model.FermentationStep(step='SECONDARY', days=14, fahrenheit=35), model.FermentationStep(step='TERTIARY', days=31, fahrenheit=35) ]) steps = recipe.fermentation_steps assert steps[0].step == 'PRIMARY' assert steps[0].days == 7 assert steps[0].fahrenheit == 50 assert steps[0].recipe == recipe assert steps[1].step == 'SECONDARY' assert steps[1].days == 14 assert steps[1].fahrenheit == 35 assert steps[1].recipe == recipe assert steps[2].step == 'TERTIARY' assert steps[2].days == 31 assert steps[2].fahrenheit == 35 assert steps[2].recipe == recipe
def test_celcius(self): recipe = model.Recipe() recipe.fermentation_steps.extend( [model.FermentationStep(step='PRIMARY', days=7, fahrenheit=50)]) steps = recipe.fermentation_steps s = steps[0] assert s.celsius == 10 s.celsius = 20 assert s.fahrenheit == 68 s.fahrenheit = 32 assert s.celsius == 0 s.celcius = 0 assert s.fahrenheit == 32 for i in range(0, 40): s.celsius = i assert s.celsius == i
def post(self, **kw): recipe = model.Recipe( name=kw.get('name'), type=kw.get('type'), author=request.context['user'] ) if recipe.metric: recipe.gallons = to_us(*(kw.get('volume'), 'LITER'))[0] else: recipe.gallons = kw.get('volume') recipe.fermentation_steps.append( model.FermentationStep( step='PRIMARY', days=7, fahrenheit=65 ) ) recipe.flush() # # If the recipe is created by a guest instead of an authenticated # user, store the trial recipe in a cookie. # if recipe.author is None: save_trial_recipe(recipe) # # If we have an authenticated user, and this is their first recipe, # save their choices as defaults so they'll be used again on their # next recipe. # if recipe.author and len(recipe.author.recipes) == 1: recipe.author.settings['default_recipe_type'] = recipe.type recipe.author.settings['default_recipe_volume'] = recipe.gallons redirect('/recipes/%x/%s/builder' % (recipe.id, recipe.slugs[0].slug))