Ejemplo n.º 1
0
def test_update_ingredient(mocker):
    mocked_internal_func = mocker.patch.object(ReceiptStorage,
                                               'update_ingredient')

    receipt_controller = ReceiptController(ReceiptStorage())

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

    mocked_internal_func.assert_called_with(sugar)
Ejemplo n.º 2
0
def update_ingredient(controller: ReceiptController):
    """
    Update ingredient data
    :param controller:
    :return: status message
    """
    try:
        content = json.dumps(request.json)
        ingredient = json.loads(
            content, object_hook=lambda d: ModelControllerIngredient(**d))
        controller.update_ingredient(ingredient)
    except Exception as e:
        print(e)
        return Response("Error", status=500, mimetype='application/json')

    return Response("Ok", status=200, mimetype='application/json')