Example #1
0
    def test_notes_update(self):
        model.Recipe(name='American IPA',
                     slugs=[
                         model.RecipeSlug(name='American IPA'),
                         model.RecipeSlug(name='American IPA (Revised)')
                     ],
                     author=model.User.get(1))
        model.commit()

        response = self.post('/recipes/1/american-ipa/builder?_method=PUT',
                             params={'recipe': dumps({'notes': 'ABC123'})})
        assert response.status_int == 200
        recipe = model.Recipe.query.first()
        assert recipe.notes == 'ABC123'
Example #2
0
    def test_style_remove(self):
        model.Recipe(name='American IPA',
                     slugs=[
                         model.RecipeSlug(name='American IPA'),
                         model.RecipeSlug(name='American IPA (Revised)')
                     ],
                     style=model.Style(name='Some Style'),
                     author=model.User.get(1))
        model.commit()

        response = self.post('/recipes/1/american-ipa/builder?_method=PUT',
                             params={'recipe': dumps({'style': None})})
        assert response.status_int == 200
        recipe = model.Recipe.query.first()
        assert recipe.style is None
Example #3
0
    def test_copy_multiple_slugs(self):
        r = model.Recipe(type='MASH',
                         name='Rocky Mountain River IPA',
                         gallons=5,
                         boil_minutes=60,
                         notes=u'This is my favorite recipe.')
        model.RecipeSlug(slug='secondary-slug', recipe=r)
        model.commit()

        recipe = model.Recipe.query.first()
        recipe.duplicate()
        model.commit()

        assert model.Recipe.query.count() == 2
        assert model.RecipeSlug.query.count() == 4

        r1, r2 = model.Recipe.get(1), model.Recipe.get(2)

        assert r1.type == r2.type == 'MASH'
        assert r1.name == r2.name == 'Rocky Mountain River IPA'
        assert r1.gallons == r2.gallons == 5
        assert r1.boil_minutes == r2.boil_minutes == 60
        assert r1.notes == r2.notes == u'This is my favorite recipe.'

        assert len(r1.slugs) == len(r2.slugs) == 2
        assert r1.slugs[0] != r2.slugs[0]
        assert r1.slugs[0].slug == r2.slugs[
            0].slug == 'rocky-mountain-river-ipa'
        assert r1.slugs[1] != r2.slugs[1]
        assert r1.slugs[1].slug == r2.slugs[1].slug == 'secondary-slug'
Example #4
0
    def test_fermentation_steps_update(self):
        model.Recipe(name='American IPA',
                     slugs=[
                         model.RecipeSlug(name='American IPA'),
                         model.RecipeSlug(name='American IPA (Revised)')
                     ],
                     author=model.User.get(1))
        model.commit()

        response = self.post('/recipes/1/american-ipa/builder?_method=PUT',
                             params={
                                 'recipe':
                                 dumps({
                                     'fermentation_steps': [{
                                         'step': 'PRIMARY',
                                         'days': 7,
                                         'fahrenheit': 68
                                     }, {
                                         'step': 'SECONDARY',
                                         'days': 14,
                                         'fahrenheit': 62
                                     }, {
                                         'step': 'TERTIARY',
                                         'days': 60,
                                         'fahrenheit': 38
                                     }]
                                 })
                             })
        assert response.status_int == 200
        recipe = model.Recipe.query.first()

        steps = recipe.fermentation_steps
        assert len(steps) == 3
        assert steps[0].step == 'PRIMARY'
        assert steps[0].days == 7
        assert steps[0].fahrenheit == 68
        assert steps[1].step == 'SECONDARY'
        assert steps[1].days == 14
        assert steps[1].fahrenheit == 62
        assert steps[2].step == 'TERTIARY'
        assert steps[2].days == 60
        assert steps[2].fahrenheit == 38
Example #5
0
    def test_unauthorized_lookup_trial_other_user(self):
        """
        If the recipe is a trial recipe, but is not *our* trial recipe,
        we should *not* have access to edit the recipe.
        """
        model.Recipe(name='American IPA',
                     slugs=[model.RecipeSlug(name='American IPA')])
        model.commit()

        response = self.get('/recipes/1/american-ipa/builder', status=401)
        assert response.status_int == 401
Example #6
0
    def test_unauthorized_lookup_trial_recipe(self):
        """
        If the recipe has no author, and we're logged in as any user,
        we should *not* have access to edit the recipe.
        """
        model.Recipe(name='American IPA',
                     slugs=[model.RecipeSlug(name='American IPA')])
        model.commit()

        response = self.get('/recipes/1/american-ipa/builder', status=401)
        assert response.status_int == 401
Example #7
0
    def test_name_update(self):
        model.Recipe(name='American IPA',
                     slugs=[
                         model.RecipeSlug(name='American IPA'),
                         model.RecipeSlug(name='American IPA (Revised)')
                     ],
                     author=model.User.get(1))
        model.commit()

        response = self.post('/recipes/1/american-ipa/builder?_method=PUT',
                             params={'recipe': dumps({'name': 'Some Recipe'})})
        assert response.status_int == 200
        recipe = model.Recipe.query.first()
        assert recipe.name == 'Some Recipe'

        slugs = recipe.slugs
        assert len(slugs) == 3
        assert slugs[0].slug == 'american-ipa'
        assert slugs[1].slug == 'american-ipa-revised'
        assert slugs[2].slug == 'some-recipe'
Example #8
0
    def test_mash_settings_update(self):
        model.Recipe(name='American IPA',
                     slugs=[
                         model.RecipeSlug(name='American IPA'),
                         model.RecipeSlug(name='American IPA (Revised)')
                     ],
                     author=model.User.get(1))
        model.commit()

        response = self.post('/recipes/1/american-ipa/builder?_method=PUT',
                             params={
                                 'recipe':
                                 dumps({
                                     'mash_method': 'TEMPERATURE',
                                     'mash_instructions': 'Mash for an hour.'
                                 })
                             })
        assert response.status_int == 200
        recipe = model.Recipe.query.first()
        assert recipe.mash_method == 'TEMPERATURE'
        assert recipe.mash_instructions == 'Mash for an hour.'
Example #9
0
    def test_slugs_copy_with_overrides(self):
        model.Recipe(name='Rocky Mountain River IPA',
                     slugs=[
                         model.RecipeSlug(slug=u'rocky-mountain-river-ipa'),
                         model.RecipeSlug(slug=u'my-favorite-ipa')
                     ])
        model.commit()

        recipe = model.Recipe.query.first()
        recipe.duplicate({'slugs': [model.RecipeSlug(slug='custom-slug')]})
        model.commit()

        assert model.Recipe.query.count() == 2
        assert model.RecipeSlug.query.count() == 3

        r1, r2 = model.Recipe.get(1), model.Recipe.get(2)
        assert len(r1.slugs) == 2
        assert len(r2.slugs) == 1

        assert r1.slugs[0].slug == 'rocky-mountain-river-ipa'
        assert r1.slugs[1].slug == 'my-favorite-ipa'
        assert r2.slugs[0].slug == 'custom-slug'
Example #10
0
    def test_unauthorized_lookup_draft(self):
        """
        If the recipe is published, and we're logged in as the author,
        we should *not* have access to edit the recipe in published form.
        """
        model.Recipe(name='American IPA',
                     slugs=[model.RecipeSlug(name='American IPA')],
                     author=model.User.get(1),
                     state='PUBLISHED')
        model.commit()

        response = self.get('/recipes/1/american-ipa/builder', status=401)
        assert response.status_int == 401
Example #11
0
    def test_slugs_copy(self):
        model.Recipe(name='Rocky Mountain River IPA',
                     slugs=[
                         model.RecipeSlug(slug=u'rocky-mountain-river-ipa'),
                         model.RecipeSlug(slug=u'my-favorite-ipa')
                     ])
        model.commit()

        recipe = model.Recipe.query.first()
        recipe.duplicate()
        model.commit()

        assert model.Recipe.query.count() == 2
        assert model.RecipeSlug.query.count() == 4

        r1, r2 = model.Recipe.get(1), model.Recipe.get(2)
        assert len(r1.slugs) == len(r2.slugs) == 2

        assert r1.slugs[0] != r2.slugs[0]
        assert r1.slugs[0].slug == r2.slugs[
            0].slug == 'rocky-mountain-river-ipa'

        assert r1.slugs[1] != r2.slugs[1]
        assert r1.slugs[1].slug == r2.slugs[1].slug == 'my-favorite-ipa'
Example #12
0
    def test_lookup(self):
        """
        If the recipe has an author, and we're logged in as that author,
        we should have access to edit the recipe.
        """
        model.Recipe(name='American IPA',
                     slugs=[
                         model.RecipeSlug(name='American IPA'),
                         model.RecipeSlug(name='American IPA (Revised)')
                     ],
                     author=model.User.get(1))
        model.commit()

        response = self.get('/recipes/500/american-ipa/builder', status=404)
        assert response.status_int == 404

        response = self.get('/recipes/1/american-ipa/builder')
        assert response.status_int == 200

        response = self.get('/recipes/1/american-ipa-revised/builder')
        assert response.status_int == 200

        response = self.get('/recipes/1/invalid_slug/builder', status=404)
        assert response.status_int == 404
Example #13
0
    def test_draft_merge(self):
        source = model.Recipe(type='MASH',
                              name='Rocky Mountain River IPA',
                              gallons=5,
                              boil_minutes=60,
                              notes=u'This is my favorite recipe.',
                              state=u'PUBLISHED')
        source.flush()
        primary_key = source.id
        creation_date = source.creation_date
        model.commit()

        # Make a new draft of the recipe
        model.Recipe.query.first().draft()
        model.commit()

        assert model.Recipe.query.count() == 2

        # Make a change to the draft
        draft = model.Recipe.query.filter(
            model.Recipe.state == 'DRAFT').first()
        draft.name = 'Simcoe IPA'
        draft.slugs = [model.RecipeSlug(name='simcoe-ipa')]
        draft.gallons = 10
        draft.boil_minutes = 90
        draft.notes = u'This is a modified recipe'
        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.RecipeSlug.query.count() == 1
        published = model.Recipe.query.first()

        assert published.id == primary_key
        assert published.name == 'Simcoe IPA'
        assert published.state == 'PUBLISHED'  # not modified
        assert published.creation_date == creation_date  # not modified
        assert len(published.slugs) == 1
        assert published.slugs[0].slug == 'simcoe-ipa'
        assert published.gallons == 10
        assert published.boil_minutes == 90
        assert published.notes == u'This is a modified recipe'
Example #14
0
    def test_slug_generation(self):
        slug = model.RecipeSlug(name='Beer')
        assert slug.slug == 'beer'

        slug = model.RecipeSlug(name='American Ale')
        assert slug.slug == 'american-ale'

        slug = model.RecipeSlug(name="Ryan's American Ale")
        assert slug.slug == 'ryans-american-ale'

        slug = model.RecipeSlug(name='Fancy Wit-Bier')
        assert slug.slug == 'fancy-wit-bier'

        slug = model.RecipeSlug(name='Spaced Out  IPA')
        assert slug.slug == 'spaced-out-ipa'

        slug = model.RecipeSlug(name='Holy Moly! Imperial Stout')
        assert slug.slug == 'holy-moly-imperial-stout'

        slug = model.RecipeSlug(name='$$$')
        assert slug.slug == 'custom-recipe'
Example #15
0
 def test_custom_slug(self):
     slug = model.RecipeSlug(name='American Ale', slug='custom')
     assert slug.slug == 'custom'