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

    receipt_controller = ReceiptController(ReceiptStorage())
    chocolate = ModelControllerIngredient(id=-1, name='choco', calories=100)
    sugar = ModelControllerIngredient(id=-1, name='sugar', calories=100)

    cake = ModelControllerReceipt(-1, 'cake', 'Good receipt',
                                  [chocolate, sugar])

    receipt_controller.set_receipt(cake)

    mocked_internal_func.assert_called_with(cake)
Exemplo n.º 2
0
def set_receipt(controller: ReceiptController):
    """
    Post a receipt
    :param controller:
    :return: receipt id
    """
    try:
        content = json.dumps(request.json)
        receipt = json2obj(content)
        receipt_id = controller.set_receipt(receipt)
        response = {'id': receipt_id}
    except Exception as e:
        print(e)
        return Response("Error", status=500, mimetype='application/json')

    return jsonify(response)