Ejemplo n.º 1
0
def get_receipt(controller: ReceiptController, index):
    """
    Get receipts based on receipt id
    :param controller:
    :param index:
    :return: Return response with JSON object found
    """
    try:
        receipt = controller.get_receipt(index)
        response = receipt.to_json()
    except Exception as e:
        print(e)
        return Response("Error", status=500, mimetype='application/json')

    return response
Ejemplo n.º 2
0
def get_receipt_calories(controller: ReceiptController, index):
    """
    Get calories from receipt
    :param controller:
    :param index: receipt id to get calories from
    :return: res containing calories per 100 g
    """
    try:
        receipt = controller.get_receipt(index)
        calories = receipt.get_calories()
        response = {'res': calories}
    except Exception as e:
        print(e)
        return Response("Error", status=500, mimetype='application/json')

    return response
Ejemplo n.º 3
0
def test_get_receipt(mocker):
    mocked_internal_func = mocker.patch.object(ReceiptStorage, 'get_receipt')

    chocolate = ModelControllerIngredient(id=-1, name='choco', calories=100)
    sugar = ModelControllerIngredient(id=-1, name='sugar', calories=100)
    cake = ModelControllerReceipt(-1, 'cake', 'Good receipt',
                                  [chocolate, sugar])

    mocked_internal_func.return_value = cake

    receipt_controller = ReceiptController(ReceiptStorage())

    sugar_id = 1
    read_receipt = receipt_controller.get_receipt(sugar_id)

    mocked_internal_func.assert_called_with(sugar_id)
    assert cake == read_receipt