Пример #1
0
    def test_yeast(self):
        model.Recipe(name='American IPA', author=model.User.get(1))
        model.Yeast(name='Wyeast 1056 - American Ale',
                    form='LIQUID',
                    attenuation=.75)
        model.commit()

        data = {
            u'mash': {
                u'additions': [{
                    u'use': u'MASH',
                    u'amount': 1,
                    u'use': 'PRIMARY',
                    u'ingredient': {
                        u'id': 1,
                        u'class': u'Yeast'
                    }
                }]
            }
        }

        self.post('/recipes/1/american-ipa/builder?_method=PUT',
                  params={'recipe': dumps(data)})

        assert model.RecipeAddition.query.count() == 1
        a = model.RecipeAddition.get(1)
        assert a.recipe == model.Recipe.get(1)
        assert a.amount == 1
        assert a.use == 'PRIMARY'
        assert a.yeast == model.Yeast.get(1)
Пример #2
0
    def test_hop(self):
        model.Recipe(name='American IPA', author=model.User.get(1))
        model.Hop(name='Cascade', origin='US')
        model.commit()

        data = {
            u'fermentation': {
                u'additions': [{
                    u'use': u'SECONDARY',
                    u'form': u'PELLET',
                    u'alpha_acid': 8,
                    u'amount': 16,
                    u'unit': u'OUNCE',
                    u'ingredient': {
                        u'id': 1,
                        u'class': u'Hop'
                    }
                }]
            }
        }

        self.post('/recipes/1/american-ipa/builder?_method=PUT',
                  params={'recipe': dumps(data)})

        assert model.HopAddition.query.count() == 1
        a = model.HopAddition.get(1)
        assert a.recipe == model.Recipe.get(1)
        assert a.amount == 16
        assert a.use == 'SECONDARY'
        assert a.unit == 'OUNCE'
        assert a.form == 'PELLET'
        assert a.alpha_acid == 8
        assert a.hop == model.Hop.get(1)
Пример #3
0
    def test_simple_copy_with_overrides(self):
        model.Recipe(
            type='MASH',
            name='Rocky Mountain River IPA',
            gallons=5,
            boil_minutes=60,
            notes=u'This is my favorite recipe.'
        )
        model.commit()

        recipe = model.Recipe.query.first()
        recipe.duplicate({
            'type': 'EXTRACT',
            'name': 'Simcoe IPA',
            'gallons': 10,
            'boil_minutes': 90,
            'notes': u'This is a duplicate.'
        })
        model.commit()

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

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

        assert r2.type == 'EXTRACT'
        assert r2.name == 'Simcoe IPA'
        assert r2.gallons == 10
        assert r2.boil_minutes == 90
        assert r2.notes == u'This is a duplicate.'
Пример #4
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
Пример #5
0
    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
Пример #6
0
    def test_choose_new_password(self):
        model.User(
            username='******',
            first_name=u'Ryan',
            email=u'*****@*****.**'
        )
        model.commit()

        model.PasswordResetRequest(
            code='ABC123',
            user=model.User.get(1)
        )

        response = self.post('/forgot/reset/ABC123', params={
            'email': '*****@*****.**',
            'password': '******',
            'password_confirm': 'newpass'
        })

        assert response.status_int == 302
        assert response.headers['Location'].endswith('/login')

        assert model.PasswordResetRequest.query.count() == 0
        assert model.User.validate(
            'ryan',
            'newpass'
        ) == model.User.query.first()
Пример #7
0
    def test_choose_new_password_expired(self):
        model.User(
            username='******',
            password='******',
            first_name=u'Ryan',
            email=u'*****@*****.**'
        )
        model.commit()

        response = self.post('/forgot/reset/ABC123', params={
            'email': '*****@*****.**',
            'password': '******',
            'password_confirm': 'newpass'
        })

        assert response.status_int == 200

        assert model.PasswordResetRequest.query.count() == 0
        assert model.User.validate(
            'ryan',
            'newpass'
        ) is None
        assert model.User.validate(
            'ryan',
            'testing'
        ) == model.User.query.first()
Пример #8
0
    def test_schema_failure(self):
        model.RecipeAddition(
            recipe      = model.Recipe(
                name='Rocky Mountain River IPA', 
                author=model.User.get(1)
            ),
            fermentable = model.Fermentable(
                name        = '2-Row',
                origin      = 'US',
                ppg         = 36,
                lovibond    = 2
            ),
            amount      = 12,
            unit        = 'POUND',
            use         = 'MASH'
        )
        model.commit()
       
        params = {
            'additions-0.type'          : 'RecipeAddition',
            'additions-0.amount'        : '10 lb',
            'additions-0.use'           : 'MASH',
            'additions-0.addition'      : 1
        }            

        for k in params:
            copy = params.copy()
            del copy[k]

            response = self.put('/recipes/1/rocky-mountain-river-ipa/builder/async/ingredients', params=copy, status=200)
            assert response.status_int == 200

        a = model.RecipeAddition.get(1)
        assert a.amount == 12
        assert a.unit == 'POUND'
Пример #9
0
    def test_choose_new_password_mismatch(self):
        model.User(
            username='******',
            password='******',
            first_name=u'Ryan',
            email=u'*****@*****.**'
        )
        model.commit()

        model.PasswordResetRequest(
            code='ABC123',
            user=model.User.get(1)
        )

        self.post('/forgot/reset/ABC123', params={
            'email': '*****@*****.**',
            'password': '******',
            'password_confirm': 'invalid'
        })

        assert model.PasswordResetRequest.query.count() == 1
        assert model.User.validate(
            'ryan',
            'newpass'
        ) is None
        assert model.User.validate(
            'ryan',
            'testing'
        ) == model.User.query.first()
Пример #10
0
    def test_view_published_recipe(self):
        model.Recipe(
            name='Rocky Mountain River IPA',
            author=model.User.get(1),
            state="PUBLISHED"
        )
        model.commit()

        response = self.get('/recipes/1/rocky-mountain-river-ipa/')
        assert response.status_int == 200

        model.Recipe.query.first().state = "DRAFT"
        model.commit()

        response = self.get('/recipes/1/rocky-mountain-river-ipa/', status=200)
        assert response.status_int == 200
        assert len(model.Recipe.query.first().views) == 0

        response = self.get(
            '/recipes/1/rocky-mountain-river-ipa/index.json',
            status=200
        )
        assert response.status_int == 200

        assert len(model.Recipe.query.first().views) == 0
Пример #11
0
def run():
    print "="*80
    print BLUE + "LOADING ENVIRONMENT" + ENDS
    print "="*80
    EnvCommand('env').run([sys.argv[1]])

    print BLUE + "BUILDING SCHEMA" + ENDS
    print "="*80
    try:
        print "STARTING A TRANSACTION..."
        print "="*80
        model.start()
        model.metadata.create_all()

        print BLUE + "GENERATING INGREDIENTS" + ENDS
        print "="*80
        populate()
    except:
        model.rollback()
        print "="*80
        print "%s ROLLING BACK... %s" % (RED, ENDS)
        print "="*80
        raise
    else:
        print "="*80
        print "%s COMMITING... %s" % (GREEN, ENDS)
        print "="*80
        model.commit()
Пример #12
0
    def test_metric_ingredient_amount(self):
        model.Fermentable(
            name='2-Row',
            type='MALT',
            origin='US',
            ppg=36,
            lovibond=2,
            description='Sample Description'
        )
        model.commit()
        self.b.refresh()

        for step in ('Mash', 'Boil'):
            self.b.find_element_by_link_text(step).click()

            self.b.find_element_by_link_text(
                "Add Malt/Fermentables..."
            ).click()
            self.b.find_element_by_link_text("2-Row (US)").click()

            i = self.b.find_element_by_css_selector(
                '.%s .addition .amount input' % step.lower()
            )
            i.clear()
            i.send_keys('1 kg')
            self.blur()
            time.sleep(2)

            self.b.refresh()

            i = self.b.find_element_by_css_selector(
                '.%s .addition .amount input' % step.lower()
            )
            assert i.get_attribute('value') == '1 kg'
Пример #13
0
    def run(self, args):
        super(PopulateCommand, self).run(args)
        self.load_app()

        print "=" * 80
        print BLUE + "LOADING ENVIRONMENT" + ENDS
        print "=" * 80

        print BLUE + "BUILDING SCHEMA" + ENDS
        print "=" * 80
        try:
            print "STARTING A TRANSACTION..."
            print "=" * 80
            model.start()
            model.metadata.create_all()

            print BLUE + "GENERATING INGREDIENTS" + ENDS
            print "=" * 80
            populate()
        except:
            model.rollback()
            print "=" * 80
            print "%s ROLLING BACK... %s" % (RED, ENDS)
            print "=" * 80
            raise
        else:
            print "=" * 80
            print "%s COMMITING... %s" % (GREEN, ENDS)
            print "=" * 80
            model.commit()
Пример #14
0
    def test_yeast_step(self):
        model.Yeast(
            name='Wyeast 1056 - American Ale',
            type='ALE',
            form='LIQUID',
            attenuation=.75,
            flocculation='MEDIUM/HIGH'
        )
        model.commit()
        self.b.refresh()

        self.b.find_element_by_link_text('Ferment').click()
        self.b.find_element_by_link_text('Add Yeast...').click()
        self.b.find_element_by_link_text('Wyeast 1056 - American Ale').click()

        Select(self.b.find_element_by_css_selector(
            '.ferment .addition select'
        )).select_by_visible_text('Secondary')
        time.sleep(2)

        self.b.refresh()

        assert self.b.find_element_by_css_selector(
            '.ferment .addition select'
        ).get_attribute('value') == 'SECONDARY'
Пример #15
0
    def test_change_hop_boil_time(self):
        model.Hop(
            name="Simcoe",
            origin='US',
            alpha_acid=13,
            description='Sample Description'
        )
        model.commit()
        self.b.refresh()

        self.b.find_element_by_link_text('Boil').click()

        self.b.find_element_by_link_text('Add Hops...').click()
        self.b.find_element_by_link_text("Simcoe (US)").click()

        selects = self.b.find_elements_by_css_selector(
            '.boil .addition .time select'
        )
        Select(selects[1]).select_by_visible_text('45 min')
        self.blur()
        time.sleep(2)

        self.b.refresh()

        selects = self.b.find_elements_by_css_selector(
            '.boil .addition .time select'
        )
        assert selects[1].get_attribute('value') == '45'
Пример #16
0
    def run(self, args):
        super(PopulateCommand, self).run(args)
        self.load_app()

        print "=" * 80
        print BLUE + "LOADING ENVIRONMENT" + ENDS
        print "=" * 80

        print BLUE + "BUILDING SCHEMA" + ENDS
        print "=" * 80
        try:
            print "STARTING A TRANSACTION..."
            print "=" * 80
            model.start()
            model.metadata.create_all()

            print BLUE + "GENERATING INGREDIENTS" + ENDS
            print "=" * 80
            populate()
        except:
            model.rollback()
            print "=" * 80
            print "%s ROLLING BACK... %s" % (RED, ENDS)
            print "=" * 80
            raise
        else:
            print "=" * 80
            print "%s COMMITING... %s" % (GREEN, ENDS)
            print "=" * 80
            model.commit()
Пример #17
0
    def test_multiple_pages(self):
        for i in range(51):
            R({'name': 'Simple Recipe', 'state': 'PUBLISHED'})
            model.commit()

        self._get()
        self._eq('pages', 3)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 51)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 25

        self._get({'page': '2'})
        self._eq('pages', 3)
        self._eq('current_page', 2)
        self._eq('offset', 25)
        self._eq('perpage', 25)
        self._eq('total', 51)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 25

        self._get({'page': '3'})
        self._eq('pages', 3)
        self._eq('current_page', 3)
        self._eq('offset', 50)
        self._eq('perpage', 25)
        self._eq('total', 51)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 1
Пример #18
0
    def test_statistic_caching(self):
        """
        When a recipe is published, certain statistics (like SRM) should be
        stored on a cached column so the values can be queried.
        """
        model.Recipe(
            type='MASH',
            name='Rocky Mountain River IPA',
            gallons=5,
            boil_minutes=60,
            notes=u'This is my favorite recipe.',
            state=u'DRAFT'
        )
        model.commit()

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

        assert model.Recipe.query.first().og == 1.0
        assert model.Recipe.query.first().fg == 1.0
        assert model.Recipe.query.first().abv == 0
        assert model.Recipe.query.first().srm == 0
        assert model.Recipe.query.first().ibu == 0
Пример #19
0
    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
Пример #20
0
    def test_draft_creation(self):
        model.Recipe(type='MASH',
                     name='Rocky Mountain River IPA',
                     gallons=5,
                     boil_minutes=60,
                     notes=u'This is my favorite recipe.',
                     state=u'PUBLISHED')
        model.commit()

        model.Recipe.query.first().draft()
        model.commit()

        assert model.Recipe.query.count() == 2
        source = model.Recipe.query.filter(
            model.Recipe.published_version == null()).first()  # noqa
        draft = model.Recipe.query.filter(
            model.Recipe.published_version != null()).first()  # noqa

        assert source != draft
        assert source.type == draft.type == 'MASH'
        assert source.name == draft.name == 'Rocky Mountain River IPA'
        assert source.state != draft.state
        assert draft.state == 'DRAFT'

        assert draft.published_version == source
        assert source.current_draft == draft
Пример #21
0
    def test_hop(self):
        model.Recipe(name='Rocky Mountain River IPA', author=model.User.get(1))
        model.Hop(
            name        = 'Cascade', 
            alpha_acid  = 5.5,
            origin      = 'US'
        )
        model.commit()

        self.post('/recipes/1/rocky-mountain-river-ipa/builder/async/ingredients', params={
            'type'          : 'HopAddition',
            'ingredient'    : 1,
            'use'           : 'BOIL',
            'amount'        : '0 lb',
            'duration'      : 30
        })

        assert model.HopAddition.query.count() == 1
        a = model.HopAddition.get(1)
        assert a.recipe == model.Recipe.get(1)
        assert a.use == 'BOIL'
        assert a.amount == 0
        assert a.unit == 'POUND'
        assert a.hop == model.Hop.get(1)
        assert a.minutes == 30
        assert a.alpha_acid == 5.5
Пример #22
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'
Пример #23
0
    def test_change_hop_form(self):
        model.Hop(name="Simcoe",
                  origin='US',
                  alpha_acid=13,
                  description='Sample Description')
        model.commit()
        self.b.refresh()

        for step in ('Mash', 'Boil', 'Ferment'):
            self.b.find_element_by_link_text(step).click()

            label = 'Add Dry Hops...' if step == 'Ferment' else 'Add Hops...'
            self.b.find_element_by_link_text(label).click()
            self.b.find_element_by_link_text("Simcoe (US)").click()

            s = Select(
                self.b.find_element_by_css_selector(
                    '.%s .addition .form select' % step.lower()))
            s.select_by_visible_text('Pellet')
            self.blur()
            time.sleep(2)

            self.b.refresh()

            s = self.b.find_element_by_css_selector(
                '.%s .addition .form select' % step.lower())
            assert s.get_attribute('value') == 'PELLET'
Пример #24
0
    def test_metric_ingredient_amount(self):
        model.Fermentable(name='2-Row',
                          type='MALT',
                          origin='US',
                          ppg=36,
                          lovibond=2,
                          description='Sample Description')
        model.commit()
        self.b.refresh()

        for step in ('Mash', 'Boil'):
            self.b.find_element_by_link_text(step).click()

            self.b.find_element_by_link_text(
                "Add Malt/Fermentables...").click()
            self.b.find_element_by_link_text("2-Row (US)").click()

            i = self.b.find_element_by_css_selector(
                '.%s .addition .amount input' % step.lower())
            i.clear()
            i.send_keys('1 kg')
            self.blur()
            time.sleep(2)

            self.b.refresh()

            i = self.b.find_element_by_css_selector(
                '.%s .addition .amount input' % step.lower())
            assert i.get_attribute('value') == '1 kg'
Пример #25
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'
Пример #26
0
    def test_add_malt(self):
        model.Fermentable(name='2-Row',
                          type='MALT',
                          origin='US',
                          ppg=36,
                          lovibond=2,
                          description='Sample Description')
        model.commit()
        self.b.refresh()

        for step in ('Mash', 'Boil'):
            self.b.find_element_by_link_text(step).click()

            assert len(
                self.b.find_elements_by_css_selector(
                    '.%s .ingredient-list .addition' % step.lower())) == 0

            self.b.find_element_by_link_text(
                "Add Malt/Fermentables...").click()
            self.b.find_element_by_link_text("2-Row (US)").click()

            assert len(
                self.b.find_elements_by_css_selector(
                    '.%s .ingredient-list .addition:not(:empty)' %
                    step.lower())) == 1
Пример #27
0
    def test_draft_creation(self):
        model.Recipe(
            type='MASH',
            name='Rocky Mountain River IPA',
            gallons=5,
            boil_minutes=60,
            notes=u'This is my favorite recipe.',
            state=u'PUBLISHED'
        )
        model.commit()

        model.Recipe.query.first().draft()
        model.commit()

        assert model.Recipe.query.count() == 2
        source = model.Recipe.query.filter(
            model.Recipe.published_version == null()
        ).first()  # noqa
        draft = model.Recipe.query.filter(
            model.Recipe.published_version != null()
        ).first()  # noqa

        assert source != draft
        assert source.type == draft.type == 'MASH'
        assert source.name == draft.name == 'Rocky Mountain River IPA'
        assert source.state != draft.state
        assert draft.state == 'DRAFT'

        assert draft.published_version == source
        assert source.current_draft == draft
Пример #28
0
    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
Пример #29
0
    def test_multiple_drafts(self):
        model.Recipe(
            name    = 'Rocky Mountain River IPA',
            author  = model.User.get(1),
            state   = "PUBLISHED"
        )
        model.Fermentable(
            name        = '2-Row',
            origin      = 'US',
            ppg         = 36,
            lovibond    = 2
        )
        model.commit()

        assert model.Recipe.query.count() == 1
        self.post('/recipes/1/rocky-mountain-river-ipa/draft')
        assert model.Recipe.query.count() == 2

        r1, r2 = model.Recipe.query.order_by(model.Recipe.id).all()
        assert r1.state == "PUBLISHED"
        assert r2.state == "DRAFT"
        assert r1.current_draft == r2
        assert r2.published_version == r1

        self.post('/recipes/1/rocky-mountain-river-ipa/draft')
        assert model.Recipe.query.count() == 2
Пример #30
0
 def test_copy_get(self):
     model.Recipe(name='Rocky Mountain River IPA', author=model.User.get(1))
     model.commit()
     assert self.get(
         '/recipes/1/rocky-mountain-river-ipa/copy',
         status = 405
     ).status_int == 405
Пример #31
0
    def test_copy_other_users_recipe(self):
        model.Recipe(
            name    = 'Rocky Mountain River IPA',
            author  = model.User(),
            state   = "PUBLISHED"
        )
        model.Fermentable(
            name        = '2-Row',
            origin      = 'US',
            ppg         = 36,
            lovibond    = 2
        )
        model.commit()

        assert model.Recipe.query.count() == 1
        self.post('/recipes/1/rocky-mountain-river-ipa/copy')
        assert model.Recipe.query.count() == 2

        for r in model.Recipe.query.all():
            assert r.name == 'Rocky Mountain River IPA'

        recipes = model.Recipe.query.order_by('id').all()
        assert recipes[0].author
        assert recipes[1].author
        assert recipes[0].author != recipes[1].author
        assert recipes[0].copies == [recipes[1]]
        assert recipes[1].copied_from == recipes[0]
Пример #32
0
    def test_browse_index(self):
        model.Style(name='American IPA')
        model.commit()

        response = self.get('/recipes/')
        assert response.status_int == 200
        assert len(response.namespace.get('styles')) == 1
Пример #33
0
    def test_yeast_change(self):
        model.RecipeAddition(
            recipe      = model.Recipe(
                name='Rocky Mountain River IPA', 
                author=model.User.get(1)
            ),
            yeast       = model.Yeast(
                name = 'Wyeast 1056 - American Ale',
                form = 'LIQUID',
                attenuation = .75
            ),
            amount      = 1,
            use         = 'PRIMARY'
        )
        model.commit()

        self.put('/recipes/1/rocky-mountain-river-ipa/builder/async/ingredients', params={
            'fermentation_additions-0.type'      : 'RecipeAddition',
            'fermentation_additions-0.use'       : 'SECONDARY',
            'fermentation_additions-0.amount'    : 1,
            'fermentation_additions-0.addition'  : 1
        })

        a = model.RecipeAddition.get(1)
        assert a.use == 'SECONDARY'
Пример #34
0
    def test_sort_by_name(self):
        R({'name': 'Recipe 1', 'state': 'PUBLISHED'})
        R({'name': 'Recipe 3', 'state': 'PUBLISHED'})
        R({'name': 'Recipe 2', 'state': 'PUBLISHED'})
        R({'name': 'Recipe 4', 'state': 'PUBLISHED'})
        model.commit()

        self._get({'order_by': 'name'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 4)
        self._eq('order_by', 'name')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 4
        assert self._ns['recipes'][0].name == 'Recipe 4'
        assert self._ns['recipes'][1].name == 'Recipe 3'
        assert self._ns['recipes'][2].name == 'Recipe 2'
        assert self._ns['recipes'][3].name == 'Recipe 1'

        self._get({'order_by': 'name', 'direction': 'ASC'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 4)
        self._eq('order_by', 'name')
        self._eq('direction', 'ASC')
        assert len(self._ns['recipes']) == 4
        assert self._ns['recipes'][0].name == 'Recipe 1'
        assert self._ns['recipes'][1].name == 'Recipe 2'
        assert self._ns['recipes'][2].name == 'Recipe 3'
        assert self._ns['recipes'][3].name == 'Recipe 4'
Пример #35
0
    def test_views(self):
        recipe = model.Recipe()
        for i in range(5):
            model.RecipeView(recipe=recipe)
        model.commit()

        assert len(model.Recipe.query.first().views) == 5
Пример #36
0
    def test_fermentation_step_metric_update(self):
        author = model.User.get(1)
        author.settings['unit_system'] = 'METRIC'
        recipe = model.Recipe(name='Rocky Mountain River IPA', author=author)
        recipe.fermentation_steps.append(
            model.FermentationStep(
                step = 'PRIMARY',
                days = 7,
                fahrenheit = 65
            )
        )
        model.commit()

        self.post('/recipes/1/rocky-mountain-river-ipa/builder/async/fermentation_steps?_method=put', params={
            'step'          : 1,
            'days'          : 14,
            'temperature'   : 0
        })

        recipe = model.Recipe.get(1)
        assert model.FermentationStep.query.count() == 1
        assert len(recipe.fermentation_steps) == 1
        assert recipe.fermentation_steps[0].step == 'PRIMARY'
        assert recipe.fermentation_steps[0].days == 14
        assert recipe.fermentation_steps[0].fahrenheit == 32
Пример #37
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'
Пример #38
0
    def test_remove_addition(self):
        model.Hop(name="Simcoe",
                  origin='US',
                  alpha_acid=13,
                  description='Sample Description')
        model.commit()
        self.b.refresh()

        for step in ('Mash', 'Boil', 'Ferment'):
            self.b.find_element_by_link_text(step).click()

            assert len(
                self.b.find_elements_by_css_selector(
                    '.%s .ingredient-list .addition' % step.lower())) == 0

            label = 'Add Dry Hops...' if step == 'Ferment' else 'Add Hops...'
            self.b.find_element_by_link_text(label).click()
            self.b.find_element_by_link_text("Simcoe (US)").click()
            time.sleep(2)

            assert len(
                self.b.find_elements_by_css_selector(
                    '.%s .ingredient-list .addition:not(:empty)' %
                    step.lower())) == 1

            self.b.find_element_by_css_selector(
                '.%s .ingredient-list .addition .close a' %
                step.lower()).click()
            time.sleep(2)
            self.b.refresh()

            assert len(
                self.b.find_elements_by_css_selector(
                    '.%s .ingredient-list .addition' % step.lower())) == 0
Пример #39
0
    def test_fermentable(self):
        model.Recipe(name='American IPA', author=model.User.get(1))
        model.Fermentable(name='2-Row', origin='US', ppg=36, lovibond=2)
        model.commit()

        data = {
            u'boil': {
                u'additions': [{
                    u'amount': 5,
                    u'use': 'BOIL',
                    u'duration': 15,
                    u'unit': u'POUND',
                    u'ingredient': {
                        u'id': 1,
                        u'class': 'Fermentable'
                    }
                }]
            }
        }

        self.post('/recipes/1/american-ipa/builder?_method=PUT',
                  params={'recipe': dumps(data)})

        assert model.RecipeAddition.query.count() == 1
        a = model.RecipeAddition.get(1)
        assert a.recipe == model.Recipe.get(1)
        assert a.amount == 5
        assert a.use == 'BOIL'
        assert a.duration == timedelta(minutes=15)
        assert a.unit == 'POUND'
        assert a.fermentable == model.Fermentable.get(1)
Пример #40
0
    def test_add_extract(self):
        model.Fermentable(name="Cooper's Amber LME",
                          type='EXTRACT',
                          origin='AUSTRALIAN',
                          ppg=36,
                          lovibond=13.3,
                          description='Sample Description')
        model.commit()
        self.b.refresh()

        for step in ('Mash', 'Boil'):
            self.b.find_element_by_link_text(step).click()

            assert len(
                self.b.find_elements_by_css_selector(
                    '.%s .ingredient-list .addition' % step.lower())) == 0

            self.b.find_element_by_link_text("Add Malt Extract...").click()
            self.b.find_element_by_link_text(
                "Cooper's Amber LME (Australian)").click()

            assert len(
                self.b.find_elements_by_css_selector(
                    '.%s .ingredient-list .addition:not(:empty)' %
                    step.lower())) == 1
Пример #41
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'
Пример #42
0
    def test_change_hop_aa(self):
        model.Hop(name="Simcoe",
                  origin='US',
                  alpha_acid=13,
                  description='Sample Description')
        model.commit()
        self.b.refresh()

        for step in ('Mash', 'Boil', 'Ferment'):
            self.b.find_element_by_link_text(step).click()

            label = 'Add Dry Hops...' if step == 'Ferment' else 'Add Hops...'
            self.b.find_element_by_link_text(label).click()
            self.b.find_element_by_link_text("Simcoe (US)").click()

            i = self.b.find_element_by_css_selector(
                '.%s .addition .unit input' % step.lower())
            i.clear()
            i.send_keys('12')
            self.blur()
            time.sleep(2)

            self.b.refresh()

            i = self.b.find_element_by_css_selector(
                '.%s .addition .unit input' % step.lower())
            assert i.get_attribute('value') == '12'
Пример #43
0
    def test_mash_change(self):
        model.RecipeAddition(
            recipe      = model.Recipe(
                name='Rocky Mountain River IPA', 
                author=model.User.get(1)
            ),
            fermentable = model.Fermentable(
                name        = '2-Row',
                origin      = 'US',
                ppg         = 36,
                lovibond    = 2
            ),
            amount      = 12,
            unit        = 'POUND',
            use         = 'MASH'
        )
        model.commit()

        self.put('/recipes/1/rocky-mountain-river-ipa/builder/async/ingredients', params={
            'mash_additions-0.type'          : 'RecipeAddition',
            'mash_additions-0.amount'        : '10 lb',
            'mash_additions-0.use'           : 'MASH',
            'mash_additions-0.addition'      : 1
        })

        a = model.RecipeAddition.get(1)
        assert a.use == 'MASH'
        assert a.amount == 10
        assert a.unit == 'POUND'
        assert a.ingredient == model.Fermentable.get(1)
Пример #44
0
    def setUp(self):
        super(TestAllGrainBuilder, self).setUp()

        model.Style(name='American IPA',
                    min_og=1.056,
                    max_og=1.075,
                    min_fg=1.01,
                    max_fg=1.018,
                    min_ibu=40,
                    max_ibu=70,
                    min_srm=6,
                    max_srm=15,
                    min_abv=.055,
                    max_abv=.075,
                    category_number=14,
                    style_letter='B')
        model.Style(name='Spice, Herb, or Vegetable Beer',
                    category_number=21,
                    style_letter='A')
        model.commit()

        self.get("/")
        self.b.find_element_by_link_text("Create Your Own Recipe").click()

        time.sleep(.1)
        self.b.find_element_by_id("name").clear()
        self.b.find_element_by_id("name").send_keys("Rocky Mountain River IPA")
        Select(self.b.find_element_by_id("type")).select_by_visible_text(
            "All Grain")
        self.b.find_element_by_css_selector("button.ribbon").click()
Пример #45
0
    def test_multiple_pages(self):
        for i in range(51):
            R({'name': 'Simple Recipe', 'state': 'PUBLISHED'})
            model.commit()

        self._get()
        self._eq('pages', 3)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 51)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 25

        self._get({'page': '2'})
        self._eq('pages', 3)
        self._eq('current_page', 2)
        self._eq('offset', 25)
        self._eq('perpage', 25)
        self._eq('total', 51)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 25

        self._get({'page': '3'})
        self._eq('pages', 3)
        self._eq('current_page', 3)
        self._eq('offset', 50)
        self._eq('perpage', 25)
        self._eq('total', 51)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 1
Пример #46
0
    def test_views(self):
        recipe = model.Recipe()
        for i in range(5):
            model.RecipeView(recipe=recipe)
        model.commit()

        assert len(model.Recipe.query.first().views) == 5
Пример #47
0
    def test_sort_by_name(self):
        R({'name': 'Recipe 1', 'state': 'PUBLISHED'})
        R({'name': 'Recipe 3', 'state': 'PUBLISHED'})
        R({'name': 'Recipe 2', 'state': 'PUBLISHED'})
        R({'name': 'Recipe 4', 'state': 'PUBLISHED'})
        model.commit()

        self._get({'order_by': 'name'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 4)
        self._eq('order_by', 'name')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 4
        assert self._ns['recipes'][0].name == 'Recipe 4'
        assert self._ns['recipes'][1].name == 'Recipe 3'
        assert self._ns['recipes'][2].name == 'Recipe 2'
        assert self._ns['recipes'][3].name == 'Recipe 1'

        self._get({'order_by': 'name', 'direction': 'ASC'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 4)
        self._eq('order_by', 'name')
        self._eq('direction', 'ASC')
        assert len(self._ns['recipes']) == 4
        assert self._ns['recipes'][0].name == 'Recipe 1'
        assert self._ns['recipes'][1].name == 'Recipe 2'
        assert self._ns['recipes'][2].name == 'Recipe 3'
        assert self._ns['recipes'][3].name == 'Recipe 4'
Пример #48
0
    def test_simple_copy_with_overrides(self):
        model.Recipe(type='MASH',
                     name='Rocky Mountain River IPA',
                     gallons=5,
                     boil_minutes=60,
                     notes=u'This is my favorite recipe.')
        model.commit()

        recipe = model.Recipe.query.first()
        recipe.duplicate({
            'type': 'EXTRACT',
            'name': 'Simcoe IPA',
            'gallons': 10,
            'boil_minutes': 90,
            'notes': u'This is a duplicate.'
        })
        model.commit()

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

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

        assert r2.type == 'EXTRACT'
        assert r2.name == 'Simcoe IPA'
        assert r2.gallons == 10
        assert r2.boil_minutes == 90
        assert r2.notes == u'This is a duplicate.'
Пример #49
0
    def test_browse_index(self):
        model.Style(name='American IPA')
        model.commit()

        response = self.get('/recipes/')
        assert response.status_int == 200
        assert len(response.namespace.get('styles')) == 1
Пример #50
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'
Пример #51
0
    def test_filter_by_srm(self):
        R({'name': 'Light', 'state': 'PUBLISHED', '_srm': 6})
        R({'name': 'Light/Amber', 'state': 'PUBLISHED', '_srm': 8})
        R({'name': 'Amber', 'state': 'PUBLISHED', '_srm': 12})
        R({'name': 'Amber/Brown', 'state': 'PUBLISHED', '_srm': 16})
        R({'name': 'Brown', 'state': 'PUBLISHED', '_srm': 20})
        R({'name': 'Brown/Dark', 'state': 'PUBLISHED', '_srm': 25})
        R({'name': 'Dark', 'state': 'PUBLISHED', '_srm': 30})
        model.commit()

        self._get()
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 7)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 7

        self._get({'color': 'light'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 2)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 2

        self._get({'color': 'amber'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 3)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 3

        self._get({'color': 'brown'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 3)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 3

        self._get({'color': 'dark'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 2)
        self._eq('order_by', 'last_updated')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 2
Пример #52
0
    def test_simple_publish(self):
        model.Recipe(name='Rocky Mountain River IPA', author=model.User.get(1))
        model.Fermentable(name='2-Row', origin='US', ppg=36, lovibond=2)
        model.commit()

        assert model.Recipe.query.first().state == "DRAFT"
        self.post('/recipes/1/rocky-mountain-river-ipa/builder/publish/')
        assert model.Recipe.query.first().state == "PUBLISHED"
Пример #53
0
    def test_sort_by_author_name(self):
        R({
            'name': 'Recipe 1',
            'state': 'PUBLISHED',
            'author': model.User(username='******', email='*****@*****.**')
        })
        R({
            'name': 'Recipe 2',
            'state': 'PUBLISHED',
            'author': model.User(username='******', email='*****@*****.**')
        })
        R({
            'name': 'Recipe 3',
            'state': 'PUBLISHED',
            'author': model.User(username='******', email='*****@*****.**')
        })
        R({
            'name': 'Recipe 4',
            'state': 'PUBLISHED',
            'author': model.User(username='******', email='*****@*****.**')
        })
        R({
            'name': 'Recipe 5',
            'state': 'PUBLISHED',
            'author': model.User(username='******', email='*****@*****.**')
        })
        model.commit()

        self._get({'order_by': 'author'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 5)
        self._eq('order_by', 'author')
        self._eq('direction', 'DESC')
        assert len(self._ns['recipes']) == 5
        assert self._ns['recipes'][0].name == 'Recipe 3'
        assert self._ns['recipes'][1].name == 'Recipe 2'
        assert self._ns['recipes'][2].name == 'Recipe 5'
        assert self._ns['recipes'][3].name == 'Recipe 4'
        assert self._ns['recipes'][4].name == 'Recipe 1'

        self._get({'order_by': 'author', 'direction': 'ASC'})
        self._eq('pages', 1)
        self._eq('current_page', 1)
        self._eq('offset', 0)
        self._eq('perpage', 25)
        self._eq('total', 5)
        self._eq('order_by', 'author')
        self._eq('direction', 'ASC')
        assert len(self._ns['recipes']) == 5
        assert self._ns['recipes'][0].name == 'Recipe 1'
        assert self._ns['recipes'][1].name == 'Recipe 4'
        assert self._ns['recipes'][2].name == 'Recipe 5'
        assert self._ns['recipes'][3].name == 'Recipe 2'
        assert self._ns['recipes'][4].name == 'Recipe 3'
Пример #54
0
    def test_view_draft_recipe_async(self):
        model.Recipe(name='Rocky Mountain River IPA',
                     author=model.User(first_name='Ryan',
                                       last_name='Petrello'),
                     state="DRAFT")
        model.commit()

        response = self.get('/recipes/1/rocky-mountain-river-ipa/', status=404)
        assert response.status_int == 404
Пример #55
0
    def test_additions_copy(self):
        recipe = model.Recipe(name=u'Sample Recipe')

        grain = model.Fermentable()
        primary_hop = model.Hop()
        bittering_hop = model.Hop()
        yeast = model.Yeast()
        recipe.additions = [
            model.RecipeAddition(use='MASH', fermentable=grain),
            model.RecipeAddition(use='MASH', hop=primary_hop),
            model.RecipeAddition(use='FIRST WORT', hop=primary_hop),
            model.RecipeAddition(
                use='BOIL',
                hop=primary_hop,
            ),
            model.RecipeAddition(use='POST-BOIL', hop=primary_hop),
            model.RecipeAddition(use='FLAME OUT', hop=bittering_hop),
            model.RecipeAddition(use='PRIMARY', yeast=yeast),
            model.RecipeAddition(use='SECONDARY', yeast=yeast)
        ]
        model.commit()

        assert model.Recipe.query.count() == 1
        assert model.RecipeAddition.query.count() == 8
        assert model.Fermentable.query.count() == 1
        assert model.Hop.query.count() == 2
        assert model.Yeast.query.count() == 1

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

        assert model.Recipe.query.count() == 2
        assert model.RecipeAddition.query.count() == 16
        assert model.Fermentable.query.count() == 1
        assert model.Hop.query.count() == 2
        assert model.Yeast.query.count() == 1

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

        for f in model.Fermentable.query.all():
            assert f in [a.ingredient for a in r1.additions]
            assert f in [a.ingredient for a in r2.additions]
            assert len(set([a.recipe for a in f.additions])) == 2

        for h in model.Hop.query.all():
            assert h in [a.ingredient for a in r1.additions]
            assert h in [a.ingredient for a in r2.additions]
            assert len(set([a.recipe for a in h.additions])) == 2

        for y in model.Yeast.query.all():
            assert y in [a.ingredient for a in r1.additions]
            assert y in [a.ingredient for a in r2.additions]
            assert len(set([a.recipe for a in y.additions])) == 2
Пример #56
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
Пример #57
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
Пример #58
0
    def test_lookup(self):
        model.Fermentable(name='2-Row',
                          type='MALT',
                          origin='US',
                          ppg=36,
                          lovibond=2,
                          description='Sample Description')
        model.commit()

        assert self.get('/ingredients/1').status_int == 200
        assert self.get('/ingredients/2', status=404).status_int == 404
Пример #59
0
    def test_valid_login(self):
        model.User(username='******', password='******')
        model.commit()

        response = self.post('/login',
                             params={
                                 'username': '******',
                                 'password': '******'
                             })

        assert response.request.environ['beaker.session']['user_id'] == 1
Пример #60
0
    def test_author_copy(self):
        model.Recipe(name='Rocky Mountain River IPA', author=model.User())
        model.commit()

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

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

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