File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,18 @@ def mirror(name):
52
52
return create_response (data )
53
53
54
54
55
- # TODO: Implement the rest of the API here!
55
+ # part 1 and 3
56
+ @app .route ("/users" , methods = ["GET" ])
57
+ def users ():
58
+ team = request .args .get ("team" )
59
+ if not team :
60
+ data = {"users" : db .get ("users" )}
61
+ return create_response (data )
62
+ users = db .get ("users" )
63
+ team_users = [u for u in users if u ["team" ] == team ]
64
+ data = {"users" : team_users }
65
+ return create_response (data )
66
+
56
67
57
68
"""
58
69
~~~~~~~~~~~~ END API ~~~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -39,3 +39,19 @@ def test_get_user_id(client):
39
39
res_user = res .json ["result" ]["user" ]
40
40
assert res_user ["name" ] == "Aria"
41
41
assert res_user ["age" ] == 19
42
+
43
+
44
+ def test_create_user (client ):
45
+
46
+ # Test successful request
47
+ body = {"name" : "David" , "age" : 100 , "team" : "Kiva" }
48
+ res = client .post ("/users" , json = body )
49
+ assert res .status_code == 201
50
+ res_user = res .json ["result" ]["user" ]
51
+ assert res_user ["name" ] == "David"
52
+
53
+ # Test bad request
54
+ body = {"name" : "Lato" , "age" : 28 }
55
+ res = client .post ("/users" , json = body )
56
+ assert res .status_code == 422
57
+ assert len (res .json ["message" ]) > 0
You can’t perform that action at this time.
0 commit comments