Exemplo n.º 1
0
def test_set_ingredient_call_storage_properly(mocker):
    mocked_internal_func = mocker.patch.object(ReceiptStorage,
                                               'set_ingredient')

    receipt_controller = ReceiptController(ReceiptStorage())

    sugar = ModelControllerIngredient(id=-1, name='sugar', calories=100)
    receipt_controller.set_ingredient(sugar)

    mocked_internal_func.assert_called_with(sugar)
Exemplo n.º 2
0
def set_ingredient(controller: ReceiptController):
    """
    Post ingredient from json data
    :param controller:
    :return: status message
    """
    try:
        content = json.dumps(request.json)
        ingredient = json.loads(
            content, object_hook=lambda d: ModelControllerIngredient(**d))
        ingredient_id = controller.set_ingredient(ingredient)
        response = {'id': ingredient_id}
    except Exception as e:
        print(e)
        return Response("Error", status=500, mimetype='application/json')

    return jsonify(response)