コード例 #1
0
ファイル: test_recipes.py プロジェクト: boncheff/cookbook
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
コード例 #2
0
ファイル: test_recipes.py プロジェクト: boncheff/cookbook
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
コード例 #3
0
ファイル: test_recipes.py プロジェクト: boncheff/cookbook
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"
コード例 #4
0
ファイル: test_recipes.py プロジェクト: boncheff/cookbook
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
コード例 #5
0
from cookbook.config import Config
from cookbook.app import app

config = Config(TESTING=True)
app.testing = True
client = app.test_client()
コード例 #6
0
ファイル: test_recipes.py プロジェクト: boncheff/cookbook
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"}
コード例 #7
0
ファイル: test_recipes.py プロジェクト: boncheff/cookbook
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
コード例 #8
0
ファイル: test_recipes.py プロジェクト: boncheff/cookbook
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"}
コード例 #9
0
ファイル: test_recipes.py プロジェクト: boncheff/cookbook
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"}