From 8a8a3cdf8c3324c8988de50b6ac7d59d6322144e Mon Sep 17 00:00:00 2001 From: Anggie Alava Date: Sun, 10 Mar 2024 11:29:32 -0500 Subject: [PATCH] Added a solution.hide.py with the guide code, and corrected repeated function names in the test.py --- .../07.1-test-post-todo/solution.hide.py | 21 +++++++++++++++++++ .learn/exercises/07.1-test-post-todo/test.py | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .learn/exercises/07.1-test-post-todo/solution.hide.py diff --git a/.learn/exercises/07.1-test-post-todo/solution.hide.py b/.learn/exercises/07.1-test-post-todo/solution.hide.py new file mode 100644 index 00000000..7861308d --- /dev/null +++ b/.learn/exercises/07.1-test-post-todo/solution.hide.py @@ -0,0 +1,21 @@ +from flask import Flask, jsonify, request +app = Flask(__name__) + +todos = [{"label": "A dummy todo", "done": True}] + + +@app.route('/todos', methods=['GET']) +def hello_world(): + return jsonify(todos) + + +@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' + + +# 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) diff --git a/.learn/exercises/07.1-test-post-todo/test.py b/.learn/exercises/07.1-test-post-todo/test.py index 04df79e0..bc483a98 100644 --- a/.learn/exercises/07.1-test-post-todo/test.py +++ b/.learn/exercises/07.1-test-post-todo/test.py @@ -95,7 +95,7 @@ def test_return(client): @pytest.mark.it("Pass the todo list to the jsonify function and return the output of the function") -def test_return(client): +def test_return_json(client): response = client.get('/todos') _body = json.loads(response.data) @@ -116,6 +116,6 @@ def test_add_new_todo(): @pytest.mark.it("The endpoint POST /todos should exist") -def test_return(client): +def test_return_endpoint(client): response = client.post('/todos', json=json.dumps({})) assert response.status_code in [200, 201]