Пример #1
0
def test_recipe_get_all(client):
    chicken_soup = Recipe(name='chicken soup', servings=10, description="delicious")
    brisket = Recipe(name='brisket', description="smoky flavours")
    db.session.add(chicken_soup)
    db.session.add(brisket)
    db.session.commit()

    response = client.get("/recipes")
    parsed_response = json.loads(response.data)
    assert parsed_response[0]['name'] == chicken_soup.name
    assert parsed_response[1]['name'] == brisket.name
Пример #2
0
 def test_calendar_with_one_day_filled(self):
     c = Calendar(year=2018, month=5)
     r = Recipe(title='temporary')
     r.save()
     c.day01recipe0 = r
     c.day01recipe1 = r
     c.save()
     url_path = reverse('planner:api:calendar-monthly-data', args=[1])
     response = self.client.get(url_path)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     response_data = response.json()
     self.assertEqual(u'1', response_data['id'])
Пример #3
0
 def test_filled_calendar(self):
     c = Calendar(nickname='CalendarMonth', year=2018, month=1)
     c.save()
     r1 = Recipe(title='Recipe')
     r2 = Recipe(title='Recipe2')
     r1.save()
     r2.save()
     c.day01recipe0 = r1
     c.day01recipe1 = r2
     c.day05recipe0 = r2
     c.day23recipe0 = r2
     c.day23recipe1 = r1
     c.day31recipe1 = r1
     c.save()
     self.assertEqual([None, None], c.get_recipes_for_day_of_month(
         'a'))  # might throw exception in the future
     self.assertEqual([None, None], c.get_recipes_for_day_of_month(
         -10))  # might throw exception in the future
     self.assertEqual([None, None], c.get_recipes_for_day_of_month(
         0))  # might throw exception in the future
     self.assertEqual([r1, r2], c.get_recipes_for_day_of_month(1))
     self.assertEqual([r2, None], c.get_recipes_for_day_of_month(5))
     self.assertEqual([r2, r1], c.get_recipes_for_day_of_month(23))
     self.assertEqual([None, r1], c.get_recipes_for_day_of_month(31))
     self.assertEqual([None, None], c.get_recipes_for_day_of_month(
         32))  # might throw exception in the future
Пример #4
0
def recipe():
    chicken_soup = Recipe(name='chicken soup',
                          servings=10,
                          description="delicious")
    db.session.add(chicken_soup)
    db.session.commit()
    return chicken_soup
Пример #5
0
 def poor_recipes(self, request):
     if request.user.is_anonymous:
         return JsonResponse(
             {'message': 'Must be logged in to get poor recipe list!'},
             status=status.HTTP_403_FORBIDDEN)
     return JsonResponse(
         {'poor_recipes': Recipe.get_poor_recipes(request.user.id)})
Пример #6
0
def test_recipe_delete(client):
    brisket = Recipe(name='brisket', description="smoky flavours")
    db.session.add(brisket)
    db.session.commit()

    response = client.delete(f"/recipes/{brisket.id}")
    assert response.status_code == 204
Пример #7
0
def test_recipe_get(client):
    brisket = Recipe(name='brisket', description="smoky flavours")
    db.session.add(brisket)
    db.session.commit()

    response = client.get(f"/recipes/{brisket.id}")
    parsed_response = json.loads(response.data)
    assert parsed_response['name'] == brisket.name
Пример #8
0
class Recipes(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('name', type = str, location = 'json')
        self.reqparse.add_argument('description', type = str, location = 'json')
        self.reqparse.add_argument('servings', type = int, location = 'json')

    @marshal_with(Recipe.fields())
    def get(self, id=None):
        if id is None:
            recipes = Recipe.query.all()
            return recipes
        
        recipe = Recipe.query.get(id)
        return recipe, 200

    @marshal_with(Recipe.fields())
    def post(self):
        args = self.reqparse.parse_args()
        recipe = Recipe(
            name=args["name"], 
            servings=args["servings"], 
            description=args["description"]
        )
        db.session.add(recipe)
        db.session.commit()
        return recipe, 201

    @marshal_with(Recipe.fields())
    def put(self, id):
        recipe = Recipe.query.get(id)
        args = self.reqparse.parse_args()

        for key, value in args.items():
            if value is not None: 
                setattr(recipe, key, value)

        db.session.commit()
        return recipe, 200

    @marshal_with(Recipe.fields())
    def delete(self, id):
        Recipe.query.filter_by(id = id).delete()
        db.session.commit()
        return {}, 204
Пример #9
0
 def post(self):
     args = self.reqparse.parse_args()
     recipe = Recipe(
         name=args["name"], 
         servings=args["servings"], 
         description=args["description"]
     )
     db.session.add(recipe)
     db.session.commit()
     return recipe, 201
Пример #10
0
 def test_calendar_shows_today_properly(self):
     today = datetime.datetime.now(tzlocal())
     c = Calendar(year=today.year, month=today.month)
     r = Recipe(title='temporary')
     r.save()
     c.day01recipe0 = r
     c.day01recipe1 = r
     c.save()
     url_path = reverse('planner:api:calendar-monthly-data', args=[1])
     response = self.client.get(url_path)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     response_data = response.json()
     date_data = response_data['data']
     for week in date_data:
         for day in week:
             if day['date_number'] == today.day:
                 self.assertTrue(day['is_today'])
             else:
                 self.assertFalse(day['is_today'])
Пример #11
0
def test_recipe_put(client):
    brisket = Recipe(name='brisket', description="smoky flavours")
    db.session.add(brisket)
    db.session.commit()

    body = {
        "name": "dog beef", 
        "servings": 3
    }

    response = client.put(f"/recipes/{brisket.id}", data=json.dumps(body), content_type='application/json')
    parsed_response = json.loads(response.data)
    assert parsed_response['name'] == body['name']
    assert parsed_response['servings'] == body['servings']
    assert parsed_response['description'] == brisket.description
Пример #12
0
 def setUp(self):
     r = Recipe()
     r.save()
Пример #13
0
from recipes.main import app, db
from recipes.models.recipe import Recipe
from recipes.models.ingredient import Ingredient

with app.app_context():
    recipe = Recipe(name='salad')
    ing = Ingredient(name='leaf', recipe=recipe)
    db.session.add(ing)
    db.session.commit()
    print(recipe)

Пример #14
0
 def handle(self, *args, **options):
     for recipe in Recipe.get_poor_recipes():
         print("Found dumb recipe: %s" % recipe.title)
Пример #15
0
 def test_ingredient_with_title_only(self):
     title_string = 'This is a normal recipe'
     titled_recipe = Recipe(title=title_string)
     self.assertIs(str(titled_recipe), title_string)
     self.assertEqual(titled_recipe.recipe_type, "Unknown")
Пример #16
0
# CONTROLLER FILE
from flask import render_template, request, redirect, session, flash
from recipes import app

# import from Friend class
from recipes.models.recipe import Recipe

from flask_bcrypt import Bcrypt
bcrypt = Bcrypt(app)
import re
EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$')

# instantiate
recipeData = Recipe()


class Recipes():
    def index(self):
        if 'userid' not in session:
            session['userid'] = 0
        return render_template("index.html")

    def logout(self):
        flash('you have been logged out')
        return redirect('/')

    def login(self, formdata):
        print('SESSION ID', session['userid'])
        print('HERE formdata in controller', formdata['login_email'])
        data = {"email": formdata['login_email']}
        result = recipeData.login(data)
Пример #17
0
 def test_ingredient_with_type_only(self):
     titled_recipe = Recipe(recipe_type=RecipeTypes.DESSERT)
     self.assertIs(str(titled_recipe), '')
     self.assertEqual(titled_recipe.recipe_type, RecipeTypes.DESSERT)
Пример #18
0
 def test_ingredient_fully_constructed(self):
     title_string = 'This is a normal recipe'
     titled_recipe = Recipe(title=title_string, recipe_type=RecipeTypes.DRINK)
     self.assertIs(str(titled_recipe), title_string)
     self.assertEqual(titled_recipe.recipe_type, RecipeTypes.DRINK)
Пример #19
0
 def _add_recipe(title):
     Recipe(title=title).save()
Пример #20
0
 def test_duplicate_recipe_titles_fails(self):
     self._add_recipe('Hey')
     r2 = Recipe(title='Hey')
     with self.assertRaises(IntegrityError):
         r2.save()
Пример #21
0
 def test_recipe_default_construction(self):
     """
     Makes sure recipe can potentially be empty...do we want this?
     """
     blank_recipe = Recipe()
     self.assertIs(str(blank_recipe), '')