From b4bbd5f047eab5f9408a0a8bc011bd2be8b380f9 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:10:20 +0100 Subject: [PATCH 01/38] Update README.md --- .learn/exercises/05-returning-json/README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.learn/exercises/05-returning-json/README.md b/.learn/exercises/05-returning-json/README.md index b2a3f181..256e1445 100644 --- a/.learn/exercises/05-returning-json/README.md +++ b/.learn/exercises/05-returning-json/README.md @@ -2,22 +2,21 @@ REST APIs have to return data in JSON format, not HTML format. -You can use the [flask jsonify](https://flask.palletsprojects.com/en/1.1.x/api/#flask.json.jsonify) function to easily convert any of the basic data-types to JSON data like this: +You can use the [flask jsonify](https://flask.palletsprojects.com/en/1.1.x/api/#flask.json.jsonify) function to easily convert any of the basic data-types to JSON data, like this: ```python +# Add the jsonify method to your Flask import +from flask import Flask, jsonify -# add the jsonify method to your Flask import - from flask import Flask, jsonify - -# suppose you have your data in the variable named some_data - some_data = { "name": "Bobby", "lastname": "Rixer" } +# Suppose you have your data in the variable named some_data +some_data = { "name": "Bobby", "lastname": "Rixer" } @app.route('/myroute', methods=['GET']) def hello_world(): - # you can convert that variable into a json string like this + # You can convert that variable into a json string like this json_text = jsonify(some_data) - # and then you can return it to the front end in the response body like this + # And then you can return it to the front end in the response body like this return json_text ``` @@ -30,7 +29,7 @@ todos = [ ] ``` -## 📝Instructions: +## 📝 Instructions: 1. Create a global variable called `todos`. Do not declare the variable inside any function. Declare the variable in the global scope and make sure the variable contains at least one task item (our task objects) inside with the following structure: @@ -38,4 +37,4 @@ todos = [ [ { "label": "My first task", "done": False } ] ``` -2. Change the function on the GET method's endpoint from string output so that it will return the jsonified version of the global variable `todos`. +2. Change the function on the GET method's endpoint from string output so that it will return the jsonified version of the global variable `todos`. From 59de0919d3e7fbfef8854247712a1e318391d52f Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:13:53 +0100 Subject: [PATCH 02/38] Update README.es.md --- .learn/exercises/05-returning-json/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/05-returning-json/README.es.md b/.learn/exercises/05-returning-json/README.es.md index 646695bc..c4e6eabf 100644 --- a/.learn/exercises/05-returning-json/README.es.md +++ b/.learn/exercises/05-returning-json/README.es.md @@ -2,7 +2,7 @@ Las REST APIs tienen que retornar datos en formato JSON, no en formato HTML. -Puedes usar la función [flask jsonify](https://flask.palletsprojects.com/en/1.1.x/api/#flask.json.jsonify) para convertir con facilidad cualquier tipo de datos básico a JSON de esta forma: +Puedes usar la función [flask jsonify](https://flask.palletsprojects.com/en/3.0.x/api/#flask.json.jsonify) para convertir con facilidad cualquier tipo de datos básico a JSON de esta forma: ```python # añade el método jsonify a tu importación de Flask From 95a97032a4934e3ae9dfe144be1cfb6861246162 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:14:04 +0100 Subject: [PATCH 03/38] Update README.md --- .learn/exercises/05-returning-json/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/05-returning-json/README.md b/.learn/exercises/05-returning-json/README.md index 256e1445..ba95d151 100644 --- a/.learn/exercises/05-returning-json/README.md +++ b/.learn/exercises/05-returning-json/README.md @@ -2,7 +2,7 @@ REST APIs have to return data in JSON format, not HTML format. -You can use the [flask jsonify](https://flask.palletsprojects.com/en/1.1.x/api/#flask.json.jsonify) function to easily convert any of the basic data-types to JSON data, like this: +You can use the [flask jsonify](https://flask.palletsprojects.com/en/3.0.x/api/#flask.json.jsonify) function to easily convert any of the basic data-types to JSON data, like this: ```python # Add the jsonify method to your Flask import From cc6ecdf13048c5d9cec76dcf00279ba00488c882 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:21:40 +0100 Subject: [PATCH 04/38] Update README.es.md --- .../exercises/05-returning-json/README.es.md | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.learn/exercises/05-returning-json/README.es.md b/.learn/exercises/05-returning-json/README.es.md index c4e6eabf..4a1a341a 100644 --- a/.learn/exercises/05-returning-json/README.es.md +++ b/.learn/exercises/05-returning-json/README.es.md @@ -5,22 +5,22 @@ Las REST APIs tienen que retornar datos en formato JSON, no en formato HTML. Puedes usar la función [flask jsonify](https://flask.palletsprojects.com/en/3.0.x/api/#flask.json.jsonify) para convertir con facilidad cualquier tipo de datos básico a JSON de esta forma: ```python -# añade el método jsonify a tu importación de Flask - from flask import Flask, jsonify +# Añade el método jsonify a tu importación de Flask +from flask import Flask, jsonify -# supongamos que tienes tus datos en la variable some_data - some_data = { "name": "Bobby", "lastname": "Rixer" } +# Supongamos que tienes tus datos en la variable some_data +some_data = { "name": "Bobby", "lastname": "Rixer" } -@app.route('/blahblah', methods=['GET']) +@app.route('/myroute', methods=['GET']) def hello_world(): - # puedes convertir esa variable en una cadena json de la siguiente manera + # Puedes convertir esa variable en una cadena json de la siguiente manera json_text = jsonify(some_data) - # y luego puedes devolverlo al front-end en el cuerpo de la respuesta de la siguiente manera + # Y luego puedes devolverlo al front-end en el cuerpo de la respuesta de la siguiente manera return json_text ``` -Si aplicamos estos conocimientos a nuestro proyecto de todo-list, podemos crear una variable global `todos` que va a contener la lista de todos de esta forma: +Si aplicamos estos conocimientos a nuestro proyecto de todo-list, podemos crear una variable global `todos` que va a contener la lista de todos de esta forma: ```python todos = [ @@ -29,12 +29,12 @@ todos = [ ] ``` -## 📝 Instrucciones +## 📝 Instrucciones: -1. Crea una variable global todos, declárala globalmente. No la declares dentro de una función, declárala en cualquier lado pero a nivel global. Asegúrate de que la variable contenga por lo menos una tarea (task) con la siguiente estructura: +1. Crea una variable global `todos`, declárala globalmente. No la declares dentro de una función, declárala en cualquier lado pero a nivel global. Asegúrate de que la variable contenga por lo menos una tarea (task) con la siguiente estructura: ```python -{ "label": "My first task", "done": False } +[ { "label": "My first task", "done": False } ] ``` 2. Cambia la función del endpoint de tu método GET para que retorne la versión en json (Usando jsonify) de la variable de `todos` recién creada. From 33c1961b01146e9ed51c4210967e341ae0030978 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:21:43 +0100 Subject: [PATCH 05/38] Update README.md --- .learn/exercises/05-returning-json/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/05-returning-json/README.md b/.learn/exercises/05-returning-json/README.md index ba95d151..1018498e 100644 --- a/.learn/exercises/05-returning-json/README.md +++ b/.learn/exercises/05-returning-json/README.md @@ -20,7 +20,7 @@ def hello_world(): return json_text ``` -If we apply this knowledge to our ToDo-list project, we can create a global variable named `todos` that will hold the list of todos like this: +If we apply this knowledge to our todo-list project, we can create a global variable named `todos` that will hold the list of todos like this: ```python todos = [ From c8e423bf9c03105115c25c922c2ee345a51e6442 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:23:30 +0100 Subject: [PATCH 06/38] Update solution.hide.py --- .learn/exercises/05-returning-json/solution.hide.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.learn/exercises/05-returning-json/solution.hide.py b/.learn/exercises/05-returning-json/solution.hide.py index 5da6232c..9df534e5 100644 --- a/.learn/exercises/05-returning-json/solution.hide.py +++ b/.learn/exercises/05-returning-json/solution.hide.py @@ -7,6 +7,6 @@ def hello_world(): return jsonify(todos) -# These two lines should always be at the end of your app.py file. +# These two lines should always be at the end of your app.py file if __name__ == '__main__': - app.run(host='0.0.0.0', port=3245, debug=True) \ No newline at end of file + app.run(host='0.0.0.0', port=3245, debug=True) From 7ab86f9652047a0efc5e4abe64e2a219d5488270 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:37:50 +0100 Subject: [PATCH 07/38] Update test.py --- .learn/exercises/05-returning-json/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.learn/exercises/05-returning-json/test.py b/.learn/exercises/05-returning-json/test.py index dffdc5ff..5157a456 100644 --- a/.learn/exercises/05-returning-json/test.py +++ b/.learn/exercises/05-returning-json/test.py @@ -63,7 +63,7 @@ def test_labels_string(): if "label" in task: assert isinstance(task["label"], str) -@pytest.mark.it('The value of the "done" key on each todo should be boolean') +@pytest.mark.it('The value of the "done" key on each todo should be a boolean') def test_done_bool(): from src import app for task in app.todos: @@ -84,4 +84,4 @@ def test_return(client): for task in _body: assert "label" in task - assert "done" in task \ No newline at end of file + assert "done" in task From 1377701dd200588896b213abc217ba3c5ae92bf6 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:57:57 +0100 Subject: [PATCH 08/38] Update README.md --- .learn/exercises/06-check-for-live/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/06-check-for-live/README.md b/.learn/exercises/06-check-for-live/README.md index 97b86ba4..3df0cc85 100644 --- a/.learn/exercises/06-check-for-live/README.md +++ b/.learn/exercises/06-check-for-live/README.md @@ -1,5 +1,5 @@ # `06` Check the API -Now you can check your endpoint live in the browser. It should be returning the list of todos in JSON format like this: +Now you can check your endpoint live in the browser. It should be returning the list of todos in JSON format, like this: ![check live todos](../../assets/return_todos.gif?raw=true) From 9e427356f6ca26084e83696aa813db168cd73d5c Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:06:42 +0100 Subject: [PATCH 09/38] Update README.md --- .learn/exercises/07-post_todo/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/07-post_todo/README.md b/.learn/exercises/07-post_todo/README.md index e80d7de8..ccfcedbe 100644 --- a/.learn/exercises/07-post_todo/README.md +++ b/.learn/exercises/07-post_todo/README.md @@ -8,7 +8,7 @@ POST /todos DELETE /todos ``` -In order to build the `POST /todos` endpoint, we have to do something similar to what we did in the first endpoint with our GET method. Remember that each endpoint in a Flask API is represented by a function ( def my_function(): ) and a decorator ( @app.route() ) like this: +In order to build the `POST /todos` endpoint, we have to do something similar to what we did in the first endpoint with our GET method. Remember that each endpoint in a Flask API is represented by decorator `@app.route()` and a function `def my_function():` like this: ```python @app.route('/myroute', methods=['GET']) @@ -23,7 +23,7 @@ Also, we are expecting to receive the TODO that the client wants to add inside o ```python from flask import request -# the request body is already json decoded and it comes in the request.json variable +# The request body is already JSON decoded, and it comes in the request.json variable print(request.json) ``` @@ -35,7 +35,7 @@ print(request.json) from flask import request ``` -2. Then, Add the folowing endpoint to your app.py and test it: +2. Then, add the following endpoint to your app.py and test it: ```python @app.route('/todos', methods=['POST']) From 1198253ec336df043b49d5add169f075f076c85d Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:34:25 +0100 Subject: [PATCH 10/38] Update README.es.md --- .learn/exercises/07-post_todo/README.es.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.learn/exercises/07-post_todo/README.es.md b/.learn/exercises/07-post_todo/README.es.md index d1338b60..6a92be63 100644 --- a/.learn/exercises/07-post_todo/README.es.md +++ b/.learn/exercises/07-post_todo/README.es.md @@ -1,4 +1,4 @@ -# `07` POST /todos (añade un nuevo task) +# `07` POST /todos (add a new task) Ahora que ya está hecho el método GET `/todos`, debemos pensar en el resto de los endpoints de nuestra API: @@ -8,25 +8,22 @@ POST /todos DELETE /todos ``` -Para poder construir el `POST /todos` debemos hacer algo similar a lo que hicimos en el primer endpoint, recuerda que cada endpoint en una Flask API está representada por una función y decorador como este: +Para poder construir el `POST /todos` debemos hacer algo similar a lo que hicimos en el primer endpoint, recuerda que cada endpoint en una Flask API está representada por una función y un decorador de esta manera: ```python -@app.route('/blabla', methods=['GET']) +@app.route('/myroute', methods=['GET']) def hello_world(): - return 'Hello, World!' + return 'Hello World!' ``` -Pero en este caso no esperaremos una solicitud `GET`. +Pero en este caso no esperaremos una solicitud `GET`, sino una solicitud `POST`. -También, esperamos recibir el `todo` (tarea) que el cliente quiere añadir dentro del `request_body` (cuerpo de la solicitud), solo que en este caso, no esperaremos una `request`(solicitud) `GET`. - -Esperamos recibir el `todo` que el cliente desea añadir dentro del `request_body`. +También, esperamos recibir el TODO que el cliente quiere añadir dentro del `request_body` (cuerpo de la solicitud). ```python from flask import request -# el request_body o cuerpo de la solicitud ya fue decodificado por json y se encuentra en la variable request.data - +# El request_body o cuerpo de la solicitud ya está decodificado en formato JSON y se encuentra en la variable request.data print(request.data) ``` From 807ff348cc5f3d63f6ce51bd3bfc2eae992676fe Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:34:28 +0100 Subject: [PATCH 11/38] Update README.md --- .learn/exercises/07-post_todo/README.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/.learn/exercises/07-post_todo/README.md b/.learn/exercises/07-post_todo/README.md index ccfcedbe..aa786a59 100644 --- a/.learn/exercises/07-post_todo/README.md +++ b/.learn/exercises/07-post_todo/README.md @@ -8,12 +8,12 @@ POST /todos DELETE /todos ``` -In order to build the `POST /todos` endpoint, we have to do something similar to what we did in the first endpoint with our GET method. Remember that each endpoint in a Flask API is represented by decorator `@app.route()` and a function `def my_function():` like this: +In order to build the `POST /todos` endpoint, we have to do something similar to what we did in the first endpoint with our GET method. Remember that each endpoint in a Flask API is represented by decorator and a function, like this: ```python @app.route('/myroute', methods=['GET']) def hello_world(): - return 'Hello, World!' + return 'Hello World!' ``` In this case, we are not going to be expecting a `GET` request, but rather a `POST` request. @@ -23,19 +23,13 @@ Also, we are expecting to receive the TODO that the client wants to add inside o ```python from flask import request -# The request body is already JSON decoded, and it comes in the request.json variable -print(request.json) +# The request body is already JSON decoded, and it comes in the request.data variable +print(request.data) ``` ## 📝 Instructions: -1. Remember to import `request` at the top of the file: - -```python -from flask import request -``` - -2. Then, add the following endpoint to your app.py and test it: +1. Add the following endpoint to your `app.py` and test it: ```python @app.route('/todos', methods=['POST']) @@ -44,3 +38,11 @@ def add_new_todo(): print("Incoming request with the following body", request_body) return 'Response for the POST todo' ``` + +2. Remember to import `request` at the top of the file: + +```python +from flask import request +``` + + From 7ac0dc019c58ae7ef7015c69bf3f4f7fde4502ed Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:35:37 +0100 Subject: [PATCH 12/38] Update solutions.hide.py --- .learn/exercises/07-post_todo/solutions.hide.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.learn/exercises/07-post_todo/solutions.hide.py b/.learn/exercises/07-post_todo/solutions.hide.py index a561d94a..26c88139 100644 --- a/.learn/exercises/07-post_todo/solutions.hide.py +++ b/.learn/exercises/07-post_todo/solutions.hide.py @@ -14,6 +14,6 @@ def add_new_todo(): return 'Response for the POST todo' -# These two lines should always be at the end of your app.py file. +# These two lines should always be at the end of your app.py file if __name__ == '__main__': - app.run(host='0.0.0.0', port=3245, debug=True) \ No newline at end of file + app.run(host='0.0.0.0', port=3245, debug=True) From d05bd00bfe9438c74ca56f3816dadc949b1a93da Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:36:21 +0100 Subject: [PATCH 13/38] Update test.py --- .learn/exercises/05-returning-json/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.learn/exercises/05-returning-json/test.py b/.learn/exercises/05-returning-json/test.py index 5157a456..395b3d0a 100644 --- a/.learn/exercises/05-returning-json/test.py +++ b/.learn/exercises/05-returning-json/test.py @@ -16,11 +16,11 @@ def client(): os.close(db_fd) os.unlink(app.config['DATABASE']) -@pytest.mark.it("folder src must exist") +@pytest.mark.it("Folder src must exist") def test_src_folder(): assert os.path.isdir("./src/") -@pytest.mark.it("app.py must exist") +@pytest.mark.it("File app.py must exist") def test_pipfile_exists(): assert os.path.isfile("src/app.py") From 9bb3c1ff041bd2d4d36c0807c272eb0ea0bdcd22 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:26:48 +0100 Subject: [PATCH 14/38] Update test.py --- .learn/exercises/07-post_todo/test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/07-post_todo/test.py b/.learn/exercises/07-post_todo/test.py index ae0c46f4..8b0391a4 100644 --- a/.learn/exercises/07-post_todo/test.py +++ b/.learn/exercises/07-post_todo/test.py @@ -16,11 +16,11 @@ def client(): os.close(db_fd) os.unlink(app.config['DATABASE']) -@pytest.mark.it("folder src must exist") +@pytest.mark.it("Folder src must exist") def test_src_folder(): assert os.path.isdir("./src/") -@pytest.mark.it("app.py must exist") +@pytest.mark.it("File app.py must exist") def test_pipfile_exists(): assert os.path.isfile("src/app.py") @@ -63,7 +63,7 @@ def test_labels_string(): if "label" in task: assert isinstance(task["label"], str) -@pytest.mark.it('The value of the "done" key on each todo should be boolean') +@pytest.mark.it('The value of the "done" key on each todo should be a boolean') def test_done_bool(): from src import app for task in app.todos: From 6ce77932588156f6b24405da2b422f54c48a16cc Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:41:07 +0100 Subject: [PATCH 15/38] Update README.md --- .learn/exercises/07-post_todo/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/07-post_todo/README.md b/.learn/exercises/07-post_todo/README.md index aa786a59..c8003055 100644 --- a/.learn/exercises/07-post_todo/README.md +++ b/.learn/exercises/07-post_todo/README.md @@ -23,8 +23,8 @@ Also, we are expecting to receive the TODO that the client wants to add inside o ```python from flask import request -# The request body is already JSON decoded, and it comes in the request.data variable -print(request.data) +# The request body is already JSON decoded, and it comes in the request.json variable +print(request.json) ``` ## 📝 Instructions: @@ -34,7 +34,7 @@ print(request.data) ```python @app.route('/todos', methods=['POST']) def add_new_todo(): - request_body = request.data + request_body = request.json print("Incoming request with the following body", request_body) return 'Response for the POST todo' ``` From 16977e6effc5631e80c2e040184eac40a74c765b Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:41:23 +0100 Subject: [PATCH 16/38] Update README.es.md --- .learn/exercises/07-post_todo/README.es.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/07-post_todo/README.es.md b/.learn/exercises/07-post_todo/README.es.md index 6a92be63..dce1dc26 100644 --- a/.learn/exercises/07-post_todo/README.es.md +++ b/.learn/exercises/07-post_todo/README.es.md @@ -23,8 +23,8 @@ También, esperamos recibir el TODO que el cliente quiere añadir dentro del `re ```python from flask import request -# El request_body o cuerpo de la solicitud ya está decodificado en formato JSON y se encuentra en la variable request.data -print(request.data) +# El request_body o cuerpo de la solicitud ya está decodificado en formato JSON y se encuentra en la variable request.json +print(request.json) ``` ## 📝 Instrucciones: @@ -34,7 +34,7 @@ print(request.data) ```python @app.route('/todos', methods=['POST']) def add_new_todo(): - request_body = request.data + request_body = request.json print("Incoming request with the following body", request_body) return 'Response for the POST todo' ``` From db75b1f593c84e94914d889a0470628e886dd183 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:41:38 +0100 Subject: [PATCH 17/38] Update solutions.hide.py --- .learn/exercises/07-post_todo/solutions.hide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/07-post_todo/solutions.hide.py b/.learn/exercises/07-post_todo/solutions.hide.py index 26c88139..3abd01fd 100644 --- a/.learn/exercises/07-post_todo/solutions.hide.py +++ b/.learn/exercises/07-post_todo/solutions.hide.py @@ -9,7 +9,7 @@ def hello_world(): @app.route('/todos', methods=['POST']) def add_new_todo(): - request_body = request.data + request_body = request.json print("Incoming request with the following body", request_body) return 'Response for the POST todo' From 701565da76134671bb3d6196cbbd5536076a3a47 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:47:28 +0100 Subject: [PATCH 18/38] Update README.es.md --- .learn/exercises/07.1-test-post-todo/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/07.1-test-post-todo/README.es.md b/.learn/exercises/07.1-test-post-todo/README.es.md index 4d9cc2e7..c8fca903 100644 --- a/.learn/exercises/07.1-test-post-todo/README.es.md +++ b/.learn/exercises/07.1-test-post-todo/README.es.md @@ -5,7 +5,7 @@ Hasta ahora esto lo que tienes sobre el endpoint `POST /todos`, tomate el tiempo ```python @app.route('/todos', methods=['POST']) def add_new_todo(): - request_body = request.data + request_body = request.json print("Incoming request with the following body", request_body) return 'Response for the POST todo' ``` From 31cf8b978f02f69eb0c6675069a966a3547cee21 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:50:06 +0100 Subject: [PATCH 19/38] Update test.py --- .learn/exercises/07.1-test-post-todo/test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/07.1-test-post-todo/test.py b/.learn/exercises/07.1-test-post-todo/test.py index 09883a76..14530ecc 100644 --- a/.learn/exercises/07.1-test-post-todo/test.py +++ b/.learn/exercises/07.1-test-post-todo/test.py @@ -16,11 +16,11 @@ def client(): os.close(db_fd) os.unlink(app.config['DATABASE']) -@pytest.mark.it("folder src must exist") +@pytest.mark.it("Folder src must exist") def test_src_folder(): assert os.path.isdir("./src/") -@pytest.mark.it("app.py must exist") +@pytest.mark.it("File app.py must exist") def test_pipfile_exists(): assert os.path.isfile("src/app.py") @@ -63,7 +63,7 @@ def test_labels_string(): if "label" in task: assert isinstance(task["label"], str) -@pytest.mark.it('The value of the "done" key on each todo should be boolean') +@pytest.mark.it('The value of the "done" key on each todo should be a boolean') def test_done_bool(): from src import app for task in app.todos: From 2ff7f24d22840b5714545877f7bc25cc27a5c9c5 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:04:35 +0100 Subject: [PATCH 20/38] Update README.md --- .learn/exercises/07.2-finish-post-todo/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/07.2-finish-post-todo/README.md b/.learn/exercises/07.2-finish-post-todo/README.md index 5ef5a795..bef20ae3 100644 --- a/.learn/exercises/07.2-finish-post-todo/README.md +++ b/.learn/exercises/07.2-finish-post-todo/README.md @@ -13,13 +13,13 @@ def add_new_todo(): Now... if we want to finish our `POST` method, we have to perform the following specific actions: -+ First: Make sure that you are converting the request body into a real python data structure, like a dictionary. You can see that we already used `request.json` for that since we know the request will be in application/json. However, if that is not known, you may want to use `request.get_json(force=True)` to ignore the content type and treat it like json. ++ First: Make sure that you are converting the request body into a real Python data structure, like a dictionary. You can see that we already used `request.json` for that since we know the request will be in `application/json`. However, if that is not known, you may want to use `request.get_json(force=True)` to ignore the content type and treat it like json. + Second: Add the dictionary into the list of `todos`. + Last: Return the new list of `todos`. -Currently, this endopint is not adding anything new to our 'database' (the `todo` list). +Currently, this endppint is not adding anything new to our 'database' (the `todos` list). Let's complete our code so the endpoint can do its job - add a new task to the `todos` list. @@ -30,4 +30,4 @@ Let's complete our code so the endpoint can do its job - add a new task to the ` 2. Return the updated list `todos` to the front end. -3. Do not forget to `jsonify` your return. Why is this necessary? Ask instructor to discuss with the class. +3. Do not forget to `jsonify` your return. Why is this necessary? Ask the instructor to discuss this with the class. From 992fa6cb66a874c61c3d25e9f9310fce7a39600b Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:05:31 +0100 Subject: [PATCH 21/38] Update README.es.md --- .../07.2-finish-post-todo/README.es.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.learn/exercises/07.2-finish-post-todo/README.es.md b/.learn/exercises/07.2-finish-post-todo/README.es.md index f11cca81..7619679c 100644 --- a/.learn/exercises/07.2-finish-post-todo/README.es.md +++ b/.learn/exercises/07.2-finish-post-todo/README.es.md @@ -1,25 +1,23 @@ # `07.2` Finish the POST /todos -Ahora... si queremos terminar el post, tenemos que realizar estas acciones específicas: - -+ Primero asegúrate de convertir el cuerpo de la solicitud en una estructura de datos real de Python, como un diccionario. Ya usamos `request.json` para eso, ya que sabemos que la solicitud estará en formato application/json. Si eso no se conoce, es posible que desee usar `request.get_json(force=True)` para ignorar el tipo de contenido y tratarlo como json. - -+ Agrega el diccionario a la lista de `todos`. - -+ Devuelve la nueva lista de `todos`. - Tu código debería verse así ahora: ```python - @app.route('/todos', methods=['POST']) def add_new_todo(): request_body = request.json print("Incoming request with the following body", request_body) return 'Response for the POST todo' - ``` +Ahora... si queremos terminar el post, tenemos que realizar estas acciones específicas: + ++ Primero asegúrate de convertir el cuerpo de la solicitud en una estructura de datos real de Python, como un diccionario. Ya usamos `request.json` para eso, ya que sabemos que la solicitud estará en formato application/json. Si eso no se conoce, es posible que desee usar `request.get_json(force=True)` para ignorar el tipo de contenido y tratarlo como json. + ++ Agrega el diccionario a la lista de `todos`. + ++ Devuelve la nueva lista de `todos`. + Obviamente, este punto final actualmente no agrega nada nuevo a nuestra 'base de datos' (la lista `todo`). Completemos el código para que el punto final pueda hacer tu trabajo: agregar una nueva tarea a los `todos`. From cc938cc2668883857de07ce8d24fcbbd2f30a1bc Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:05:37 +0100 Subject: [PATCH 22/38] Update README.md --- .learn/exercises/07.2-finish-post-todo/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.learn/exercises/07.2-finish-post-todo/README.md b/.learn/exercises/07.2-finish-post-todo/README.md index bef20ae3..60e7e12b 100644 --- a/.learn/exercises/07.2-finish-post-todo/README.md +++ b/.learn/exercises/07.2-finish-post-todo/README.md @@ -3,7 +3,6 @@ Your code should look like this by now: ```python - @app.route('/todos', methods=['POST']) def add_new_todo(): request_body = request.json From a1d2ab4943e6597fdb0c4d9d46bf4bf7ecf1a733 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:17:39 +0100 Subject: [PATCH 23/38] Update README.md --- .learn/exercises/07.2-finish-post-todo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/07.2-finish-post-todo/README.md b/.learn/exercises/07.2-finish-post-todo/README.md index 60e7e12b..15ca3a79 100644 --- a/.learn/exercises/07.2-finish-post-todo/README.md +++ b/.learn/exercises/07.2-finish-post-todo/README.md @@ -18,7 +18,7 @@ Now... if we want to finish our `POST` method, we have to perform the following + Last: Return the new list of `todos`. -Currently, this endppint is not adding anything new to our 'database' (the `todos` list). +Currently, this endpoint is not adding anything new to our 'database' (the `todos` list). Let's complete our code so the endpoint can do its job - add a new task to the `todos` list. From 6c4837ea5875c872a6f5d8cf547fd8946b9247cc Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:18:59 +0100 Subject: [PATCH 24/38] Update README.es.md --- .learn/exercises/07.2-finish-post-todo/README.es.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/07.2-finish-post-todo/README.es.md b/.learn/exercises/07.2-finish-post-todo/README.es.md index 7619679c..e358cd27 100644 --- a/.learn/exercises/07.2-finish-post-todo/README.es.md +++ b/.learn/exercises/07.2-finish-post-todo/README.es.md @@ -12,13 +12,13 @@ def add_new_todo(): Ahora... si queremos terminar el post, tenemos que realizar estas acciones específicas: -+ Primero asegúrate de convertir el cuerpo de la solicitud en una estructura de datos real de Python, como un diccionario. Ya usamos `request.json` para eso, ya que sabemos que la solicitud estará en formato application/json. Si eso no se conoce, es posible que desee usar `request.get_json(force=True)` para ignorar el tipo de contenido y tratarlo como json. ++ Primero asegúrate de convertir el cuerpo de la solicitud en una estructura de datos real de Python, como un diccionario. Ya usamos `request.json` para eso, ya que sabemos que la solicitud estará en formato `application/json`. Si el formato no se conoce, es posible que deba usar `request.get_json(force=True)` para ignorar el tipo de contenido y tratarlo como json. + Agrega el diccionario a la lista de `todos`. + Devuelve la nueva lista de `todos`. -Obviamente, este punto final actualmente no agrega nada nuevo a nuestra 'base de datos' (la lista `todo`). +Obviamente, este punto final actualmente no agrega nada nuevo a nuestra 'base de datos' (la lista `todos`). Completemos el código para que el punto final pueda hacer tu trabajo: agregar una nueva tarea a los `todos`. @@ -28,4 +28,4 @@ Completemos el código para que el punto final pueda hacer tu trabajo: agregar u 2. Devuelve la lista actualizada `todos` al front end. -3. No olvide `jsonify` su devolución. ¿Por qué es esto necesario? Discuta con la clase. +3. No olvide hacer `jsonify` en lo que devuelve. ¿Por qué es esto necesario? Discuta con la clase. From cd8971806410e842207905f159ad4da1edfcad45 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:21:40 +0100 Subject: [PATCH 25/38] Update solution.hide.py --- .learn/exercises/07.2-finish-post-todo/solution.hide.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.learn/exercises/07.2-finish-post-todo/solution.hide.py b/.learn/exercises/07.2-finish-post-todo/solution.hide.py index 1e443d1c..951f5adf 100644 --- a/.learn/exercises/07.2-finish-post-todo/solution.hide.py +++ b/.learn/exercises/07.2-finish-post-todo/solution.hide.py @@ -15,6 +15,6 @@ def add_new_todo(): return jsonify(todos) -# These two lines should always be at the end of your app.py file. +# These two lines should always be at the end of your app.py file if __name__ == '__main__': - app.run(host='0.0.0.0', port=3245, debug=True) \ No newline at end of file + app.run(host='0.0.0.0', port=3245, debug=True) From bd7d04c29e79bb6e8af0cb3202883295fe0937d6 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:24:30 +0100 Subject: [PATCH 26/38] Update test.py --- .learn/exercises/07.2-finish-post-todo/test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/07.2-finish-post-todo/test.py b/.learn/exercises/07.2-finish-post-todo/test.py index abf05a2a..6783d6d4 100644 --- a/.learn/exercises/07.2-finish-post-todo/test.py +++ b/.learn/exercises/07.2-finish-post-todo/test.py @@ -16,11 +16,11 @@ def client(): os.close(db_fd) os.unlink(app.config['DATABASE']) -@pytest.mark.it("folder src must exist") +@pytest.mark.it("Folder src must exist") def test_src_folder(): assert os.path.isdir("./src/") -@pytest.mark.it("app.py must exist") +@pytest.mark.it("File app.py must exist") def test_pipfile_exists(): assert os.path.isfile("src/app.py") @@ -101,7 +101,7 @@ def test_return(client): assert response.status_code in [200, 201] -@pytest.mark.it("POST /todos should return json list of todos") +@pytest.mark.it("POST /todos should return the json list of todos") def test_simple_add(client): response = client.post('/todos', json = { "done": True, "label": "Sample Todo 2" }) assert response.status_code in [200, 201] From a0b49d7f70baec0d26855231525aab2f6c7d2d93 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:06:32 +0100 Subject: [PATCH 27/38] Update README.md --- .learn/exercises/08-delete-todo/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.learn/exercises/08-delete-todo/README.md b/.learn/exercises/08-delete-todo/README.md index 8b2e9262..cb93d04a 100644 --- a/.learn/exercises/08-delete-todo/README.md +++ b/.learn/exercises/08-delete-todo/README.md @@ -1,13 +1,13 @@ # `08` Delete todo -Deleting a todo is basically the opposite of adding a new one so you should use 90% of the code from the 'POST /todos' feature. +Deleting a todo is basically the opposite of adding a new one, so you should use 90% of the code from the 'POST /todos' feature. The main difference is that `DELETE /todos/` will receive the position to delete in the URL of the request like this: ```python @app.route('/todos/', methods=['DELETE']) def delete_todo(position): - print("This is the position to delete: ",position) + print("This is the position to delete: ", position) return 'something' ``` @@ -16,8 +16,8 @@ When you use the `<` and `>` symbols, Flask will return whatever the client spec For example: ```txt -The request DELETE /todos/1 will call the function `delete_todo` with the variable `position == 1` -The request DELETE /todos/323 will call the function `delete_todo` with the variable `position == 323` +The request DELETE /todos/1 will call the function 'delete_todo' with the variable 'position == 1' +The request DELETE /todos/323 will call the function 'delete_todo' with the variable 'position == 323' ``` ## 📝 Instructions: From 4bacc1b0e7ef5691f3bf2b75ec6e59f9e9e6c5d8 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:07:19 +0100 Subject: [PATCH 28/38] Update README.md --- .learn/exercises/08-delete-todo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/08-delete-todo/README.md b/.learn/exercises/08-delete-todo/README.md index cb93d04a..691aeddb 100644 --- a/.learn/exercises/08-delete-todo/README.md +++ b/.learn/exercises/08-delete-todo/README.md @@ -1,6 +1,6 @@ # `08` Delete todo -Deleting a todo is basically the opposite of adding a new one, so you should use 90% of the code from the 'POST /todos' feature. +Deleting a todo is basically the opposite of adding a new one, so you should use 90% of the code from the `POST /todos` feature. The main difference is that `DELETE /todos/` will receive the position to delete in the URL of the request like this: From e074fa373805b01976c5008f17240854af4387ee Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:08:22 +0100 Subject: [PATCH 29/38] Update README.es.md --- .learn/exercises/08-delete-todo/README.es.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/08-delete-todo/README.es.md b/.learn/exercises/08-delete-todo/README.es.md index 34fb926d..f55c22e8 100644 --- a/.learn/exercises/08-delete-todo/README.es.md +++ b/.learn/exercises/08-delete-todo/README.es.md @@ -7,16 +7,17 @@ La principal diferencia es que `DELETE /todos/` recibirá la posic ```python @app.route('/todos/', methods=['DELETE']) def delete_todo(position): - print("This is the position to delete: ",position) + print("This is the position to delete: ", position) return 'something' ``` Cuando usas los símbolos `<` y `>`, Flask retornará lo que sea que haya especificado el cliente en esa parte de la URL como variable. por ejemplo: ```txt -La solicitud DELETE /todos/1 llamará a la función `delete_todo` con la variable position == 1 -La solicitud DELETE /todos/323 llamará a la función `delete_todo` con la variable position == 323 +La solicitud DELETE /todos/1 llamará a la función 'delete_todo' con la variable 'position == 1' +La solicitud DELETE /todos/323 llamará a la función 'delete_todo' con la variable 'position == 323' ``` + ## 📝 Instrucciones: 1. Añade este endpoint a tu archivo `app.py`. From 238789e9cf344b0f125ef3f4d042e45f9ed62158 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:09:05 +0100 Subject: [PATCH 30/38] Update solution.hide.py --- .learn/exercises/08-delete-todo/solution.hide.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/08-delete-todo/solution.hide.py b/.learn/exercises/08-delete-todo/solution.hide.py index f135d769..5bd7b0fa 100644 --- a/.learn/exercises/08-delete-todo/solution.hide.py +++ b/.learn/exercises/08-delete-todo/solution.hide.py @@ -16,10 +16,10 @@ def add_new_todo(): @app.route('/todos/', methods=['DELETE']) def delete_todo(position): - print("This is the position to delete: ",position) + print("This is the position to delete:", position) return 'something' -# These two lines should always be at the end of your app.py file. +# These two lines should always be at the end of your app.py file if __name__ == '__main__': - app.run(host='0.0.0.0', port=3245, debug=True) \ No newline at end of file + app.run(host='0.0.0.0', port=3245, debug=True) From fd3d3fe01dce7341bd72f8bedab28d17e6885429 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:09:10 +0100 Subject: [PATCH 31/38] Update README.md --- .learn/exercises/08-delete-todo/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/08-delete-todo/README.md b/.learn/exercises/08-delete-todo/README.md index 691aeddb..39f19a79 100644 --- a/.learn/exercises/08-delete-todo/README.md +++ b/.learn/exercises/08-delete-todo/README.md @@ -7,7 +7,7 @@ The main difference is that `DELETE /todos/` will receive the posi ```python @app.route('/todos/', methods=['DELETE']) def delete_todo(position): - print("This is the position to delete: ", position) + print("This is the position to delete:", position) return 'something' ``` From a7c6cc48b2164337f074c4e501ceea16ea614d29 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:09:16 +0100 Subject: [PATCH 32/38] Update README.es.md --- .learn/exercises/08-delete-todo/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/08-delete-todo/README.es.md b/.learn/exercises/08-delete-todo/README.es.md index f55c22e8..ae324ec6 100644 --- a/.learn/exercises/08-delete-todo/README.es.md +++ b/.learn/exercises/08-delete-todo/README.es.md @@ -7,7 +7,7 @@ La principal diferencia es que `DELETE /todos/` recibirá la posic ```python @app.route('/todos/', methods=['DELETE']) def delete_todo(position): - print("This is the position to delete: ", position) + print("This is the position to delete:", position) return 'something' ``` From e4cdd62f9b55393293f041c56be5ae1166d85f25 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:14:26 +0100 Subject: [PATCH 33/38] Update test.py --- .learn/exercises/08-delete-todo/test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.learn/exercises/08-delete-todo/test.py b/.learn/exercises/08-delete-todo/test.py index 07e6e19c..3fee2bc0 100644 --- a/.learn/exercises/08-delete-todo/test.py +++ b/.learn/exercises/08-delete-todo/test.py @@ -16,11 +16,11 @@ def client(): os.close(db_fd) os.unlink(app.config['DATABASE']) -@pytest.mark.it("folder src must exist") +@pytest.mark.it("Folder src must exist") def test_src_folder(): assert os.path.isdir("./src/") -@pytest.mark.it("app.py must exist") +@pytest.mark.it("File app.py must exist") def test_pipfile_exists(): assert os.path.isfile("src/app.py") @@ -63,7 +63,7 @@ def test_labels_string(): if "label" in task: assert isinstance(task["label"], str) -@pytest.mark.it('The value of the "done" key on each todo should be boolean') +@pytest.mark.it('The value of the "done" key on each todo should be a boolean') def test_done_bool(): from src import app for task in app.todos: @@ -158,4 +158,4 @@ def test_delete(): @pytest.mark.it("The endpoint 'DELETE /todos' should exist") def test_return(client): response = client.delete('/todos/1') - assert response.status_code == 200 \ No newline at end of file + assert response.status_code == 200 From e9e22b008703cdabf229c691a42df9e1c79ec2d4 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:16:54 +0100 Subject: [PATCH 34/38] Update README.md --- .learn/exercises/08.1-delete-live-test/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.learn/exercises/08.1-delete-live-test/README.md b/.learn/exercises/08.1-delete-live-test/README.md index bd66a0ea..01f8f03b 100644 --- a/.learn/exercises/08.1-delete-live-test/README.md +++ b/.learn/exercises/08.1-delete-live-test/README.md @@ -1,13 +1,14 @@ -## `08.1` Test your endpoint +# `08.1` Test your endpoint -This is what you have so far about the `DELETE /todos/` endpoint, take some time to analyze each line: +This is what you have so far about the `DELETE /todos/` endpoint; take some time to analyze each line: ```python @app.route('/todos/', methods=['DELETE']) def delete_todo(position): - print("This is the position to delete: ",position) + print("This is the position to delete:", position) return 'something' ``` + Use Postman, Insomnia or any other API Request Builder that you like to test your API. | | | From b14ca1b801ede504f9894a81f59867c4dd800816 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:26:02 +0100 Subject: [PATCH 35/38] Update README.es.md --- .learn/exercises/08.1-delete-live-test/README.es.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.learn/exercises/08.1-delete-live-test/README.es.md b/.learn/exercises/08.1-delete-live-test/README.es.md index 3b6188ff..1028f62c 100644 --- a/.learn/exercises/08.1-delete-live-test/README.es.md +++ b/.learn/exercises/08.1-delete-live-test/README.es.md @@ -5,7 +5,7 @@ Hasta ahora esto es lo que tienes sobre el endpoint `DELETE /todos/', methods=['DELETE']) def delete_todo(position): - print("This is the position to delete: ",position) + print("This is the position to delete:", position) return 'something' ``` From 813ed25ed3460001dcc1f8d716856df0177ea579 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:30:14 +0100 Subject: [PATCH 36/38] Update test.py --- .learn/exercises/08.1-delete-live-test/test.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.learn/exercises/08.1-delete-live-test/test.py b/.learn/exercises/08.1-delete-live-test/test.py index 8345146d..2aef0936 100644 --- a/.learn/exercises/08.1-delete-live-test/test.py +++ b/.learn/exercises/08.1-delete-live-test/test.py @@ -16,11 +16,11 @@ def client(): os.close(db_fd) os.unlink(app.config['DATABASE']) -@pytest.mark.it("folder src must exist") +@pytest.mark.it("Folder src must exist") def test_src_folder(): assert os.path.isdir("./src/") -@pytest.mark.it("app.py must exist") +@pytest.mark.it("File app.py must exist") def test_pipfile_exists(): assert os.path.isfile("src/app.py") @@ -63,7 +63,7 @@ def test_labels_string(): if "label" in task: assert isinstance(task["label"], str) -@pytest.mark.it('The value of the "done" key on each todo should be boolean') +@pytest.mark.it('The value of the "done" key on each todo should be a boolean') def test_done_bool(): from src import app for task in app.todos: @@ -142,9 +142,8 @@ def test_incoming_list(client): matches.append(task) assert 1 == len(matches) -""" -Testing DELETE -""" + +# Testing DELETE @pytest.mark.it("The function delete_todo should be declared") def test_delete(): @@ -158,4 +157,4 @@ def test_delete(): @pytest.mark.it("The endpoint 'DELETE /todos' should exist") def test_return(client): response = client.delete('/todos/1') - assert response.status_code == 200 \ No newline at end of file + assert response.status_code == 200 From 18f34ccfbee3b77c6c5e03e4979928e00fd713c2 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:07:33 +0100 Subject: [PATCH 37/38] Update solution.hide.py --- .learn/exercises/08.2-finish-todos/solution.hide.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.learn/exercises/08.2-finish-todos/solution.hide.py b/.learn/exercises/08.2-finish-todos/solution.hide.py index daf8b52c..67e9cdfe 100644 --- a/.learn/exercises/08.2-finish-todos/solution.hide.py +++ b/.learn/exercises/08.2-finish-todos/solution.hide.py @@ -16,12 +16,12 @@ def add_new_todo(): @app.route('/todos/', methods=['DELETE']) def delete_todo(position): - print("This is the position to delete: ",position) + print("This is the position to delete:", position) - todos.pop((position-1)) + todos.pop(position) return jsonify(todos) -# These two lines should always be at the end of your app.py file. +# These two lines should always be at the end of your app.py file if __name__ == '__main__': - app.run(host='0.0.0.0', port=3245, debug=True) \ No newline at end of file + app.run(host='0.0.0.0', port=3245, debug=True) From 9e099c92ae6030a1c5849a97dc5a7998e17c7d3b Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:09:03 +0100 Subject: [PATCH 38/38] Update test.py --- .learn/exercises/08.2-finish-todos/test.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.learn/exercises/08.2-finish-todos/test.py b/.learn/exercises/08.2-finish-todos/test.py index 2cf4b8ec..155818ce 100644 --- a/.learn/exercises/08.2-finish-todos/test.py +++ b/.learn/exercises/08.2-finish-todos/test.py @@ -16,11 +16,11 @@ def client(): os.close(db_fd) os.unlink(app.config['DATABASE']) -@pytest.mark.it("folder src must exist") +@pytest.mark.it("Folder src must exist") def test_src_folder(): assert os.path.isdir("./src/") -@pytest.mark.it("app.py must exist") +@pytest.mark.it("File app.py must exist") def test_pipfile_exists(): assert os.path.isfile("src/app.py") @@ -63,7 +63,7 @@ def test_labels_string(): if "label" in task: assert isinstance(task["label"], str) -@pytest.mark.it('The value of the "done" key on each todo should be boolean') +@pytest.mark.it('The value of the "done" key on each todo should be a boolean') def test_done_bool(): from src import app for task in app.todos: @@ -142,9 +142,8 @@ def test_incoming_list(client): matches.append(task) assert 1 == len(matches) -""" -Testing DELETE -""" + +# Testing DELETE @pytest.mark.it("The function delete_todo should be declared") def test_delete(): @@ -175,4 +174,4 @@ def test_delete_and_get(client): response2 = client.delete('/todos/0') data = json.loads(response2.data) - assert (len(todos) - 1) == len(data) \ No newline at end of file + assert (len(todos) - 1) == len(data)