示例#1
0
    def test_fetch_recipes_with_list_constraint_by_id(self):
        """
        Constrain to a specific list by id
        """
        ul = UserList(name='Favorites', user_id=1)
        ul.save()
        UserListRecipe(recipe_id=1, user_list_id=ul.id).save()
        UserListRecipe(recipe_id=3, user_list_id=ul.id).save()
        ul2 = UserList(name='Favorites', user_id=2)
        ul2.save()
        UserListRecipe(recipe_id=2, user_list_id=ul2.id).save()

        resp = self.client.get('/api/v1/recipes/',
                               {'search': 'list = %s' % ul2.id})
        self.assertEqual(len(resp.json()['results']), 1)
        self.assertEqual([r['id'] for r in resp.json()['results']], [2])
示例#2
0
    def test_fetch_recipes_with_list_constraint_quoted(self):
        """
        Constrain to a specific list
        """
        ul = UserList(name='My Special List', user_id=1)
        ul.save()
        UserListRecipe(recipe_id=1, user_list_id=ul.id).save()

        resp = self.client.get('/api/v1/recipes/',
                               {'search': 'list = "My Special List"'})
        self.assertEqual([r['id'] for r in resp.json()['results']], [1])
示例#3
0
    def test_fetch_recipes_counts(self):
        """
        Check that user list counts and user comment counts are sent when present
        """
        ul = UserList(name='My List', user_id=1)
        ul.save()
        UserListRecipe(recipe_id=6, user_list=ul).save()
        Comment(user_id=1, recipe_id=6, text='Delicious!').save()

        resp = self.client.get('/api/v1/recipes/', {'search': 'childcare'})
        results = resp.json()['results']
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['uc_count'], 1)
        self.assertEqual(results[0]['ul_count'], 1)
示例#4
0
    def test_like_filter(self):
        r = Recipe(name='Fancy as F*ck',
                   book_id=1,
                   directions='Shake and drink')
        r.save()
        for i in [4, 9, 13]:
            q = Quantity(recipe=r,
                         amount=1,
                         unit=Uom(pk='oz'),
                         ingredient=Ingredient(pk=i))
            q.save()

        r2 = Recipe.objects.get(name='Special Counsel')
        ul = UserList(name='Favorites', user_id=1)
        ul.save()
        UserListRecipe(recipe=r2, user_list=ul).save()

        resp = self.client.get('/api/v1/recipes/',
                               {'search': 'LIKE list = %s' % ul.id})
        self.assertEqual([r['name'] for r in resp.json()['results']],
                         ['Fancy as F*ck'])