Exemplo n.º 1
0
def test_get_ingredient_call_storage_properly(mocker):
    mocked_internal_func = mocker.patch.object(ReceiptStorage,
                                               'get_ingredient')
    sugar = ModelControllerIngredient(id=-1, name='sugar', calories=100)
    mocked_internal_func.return_value = sugar
    receipt_controller = ReceiptController(ReceiptStorage())

    sugar_id = 1
    read_ingredient = receipt_controller.get_ingredient(sugar_id)

    mocked_internal_func.assert_called_with(sugar_id)
    assert sugar == read_ingredient
Exemplo n.º 2
0
def get_ingredient(controller: ReceiptController, index):
    """
    Get ingredient
    :param controller:
    :param index: ingredient id to be obtained
    :return: Return response with JSON object found
    """
    try:
        receipt = controller.get_ingredient(index)
        response = receipt.to_json()
    except Exception as e:
        print(e)
        return Response("Error", status=500, mimetype='application/json')

    return response