def test_get_all_recipes_by_cuisine_empty(): with app.test_client() as c: resp = c.get("/recipes?cuisine=ethiopian") recipes = resp.json assert resp.status_code == requests.codes.OK assert len(recipes) == 0
def test_get_all_recipes_by_cuisine_paginated(): with app.test_client() as c: resp = c.get("/recipes?cuisine=british&page=1") recipes = resp.json assert resp.status_code == requests.codes.OK assert len(recipes) == 4 resp = c.get("/recipes?cuisine=british&page=1&per_page=1") recipes = resp.json assert resp.status_code == requests.codes.OK assert len(recipes) == 1 assert recipes[0]["id"] == '3' resp = c.get("/recipes?cuisine=british&page=2&per_page=1") recipes = resp.json assert resp.status_code == requests.codes.OK assert len(recipes) == 1 assert recipes[0]["id"] == '4' resp = c.get("/recipes?cuisine=british&page=3&per_page=1") recipes = resp.json assert resp.status_code == requests.codes.OK assert len(recipes) == 1 assert recipes[0]["id"] == '5' resp = c.get("/recipes?cuisine=british&page=100&per_page=1") recipes = resp.json assert resp.status_code == requests.codes.OK assert len(recipes) == 0
def test_get_one_recipe(): with app.test_client() as c: resp = c.get("/recipes/2") recipe = resp.json assert resp.status_code == requests.codes.OK assert recipe is not None assert recipe["title"] == "Tamil Nadu Prawn Masala" assert recipe["protein_source"] == "seafood"
def test_patch_recipe_ok(): with app.test_client() as c: resp = c.get("/recipes/2") recipe = resp.json assert resp.status_code == requests.codes.OK assert recipe is not None payload = {"recipe_cuisine": "jamaican", "calories_kcal": '1001'} resp = c.patch("/recipes/2", headers=HEADERS, json=payload) assert resp.status_code == requests.codes.OK updated_recipe = resp.json for k, v in payload.items(): assert updated_recipe[k] == v
from cookbook.config import Config from cookbook.app import app config = Config(TESTING=True) app.testing = True client = app.test_client()
def test_get_one_recipes_not_found(): with app.test_client() as c: resp = c.get("/recipes/0") assert resp.status_code == requests.codes.NOT_FOUND assert resp.json == {"message": "Not Found"}
def test_get_all_recipes(): with app.test_client() as c: resp = c.get("/recipes") assert resp.status_code == requests.codes.OK assert len(resp.json) == 10
def test_patch_recipe_invalid_field(): with app.test_client() as c: payload = {"cook": "Ramsay"} resp = c.patch("/recipes/2", headers=HEADERS, json=payload) assert resp.status_code == requests.codes.BAD_REQUEST assert resp.json == {"message": "Error updating recipe"}
def test_patch_recipe_empty_payload(): with app.test_client() as c: resp = c.patch("/recipes/2", headers=HEADERS, json={}) assert resp.status_code == requests.codes.BAD_REQUEST assert resp.json == {"message": "Invalid Payload"}