File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
.learn/exercises/07.1-test-post-todo Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 1+ from flask import Flask , jsonify , request
2+ app = Flask (__name__ )
3+
4+ todos = [{"label" : "A dummy todo" , "done" : True }]
5+
6+
7+ @app .route ('/todos' , methods = ['GET' ])
8+ def hello_world ():
9+ return jsonify (todos )
10+
11+
12+ @app .route ('/todos' , methods = ['POST' ])
13+ def add_new_todo ():
14+ request_body = request .json
15+ print ("Incoming request with the following body" , request_body )
16+ return 'Response for the POST todo'
17+
18+
19+ # These two lines should always be at the end of your app.py file
20+ if __name__ == '__main__' :
21+ app .run (host = '0.0.0.0' , port = 3245 , debug = True )
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ def test_return(client):
9595
9696
9797@pytest .mark .it ("Pass the todo list to the jsonify function and return the output of the function" )
98- def test_return (client ):
98+ def test_return_json (client ):
9999 response = client .get ('/todos' )
100100 _body = json .loads (response .data )
101101
@@ -116,6 +116,6 @@ def test_add_new_todo():
116116
117117
118118@pytest .mark .it ("The endpoint POST /todos should exist" )
119- def test_return (client ):
119+ def test_return_endpoint (client ):
120120 response = client .post ('/todos' , json = json .dumps ({}))
121121 assert response .status_code in [200 , 201 ]
You can’t perform that action at this time.
0 commit comments