Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples to help #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,18 @@ def mirror(name):
return create_response(data)


# TODO: Implement the rest of the API here!
# part 1 and 3
@app.route("/users", methods=["GET"])
def users():
team = request.args.get("team")
if not team:
data = {"users": db.get("users")}
return create_response(data)
users = db.get("users")
team_users = [u for u in users if u["team"] == team]
data = {"users": team_users}
return create_response(data)


"""
~~~~~~~~~~~~ END API ~~~~~~~~~~~~
Expand Down
16 changes: 16 additions & 0 deletions test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,19 @@ def test_get_user_id(client):
res_user = res.json["result"]["user"]
assert res_user["name"] == "Aria"
assert res_user["age"] == 19


def test_create_user(client):

# Test successful request
body = {"name": "David", "age": 100, "team": "Kiva"}
res = client.post("/users", json=body)
assert res.status_code == 201
res_user = res.json["result"]["user"]
assert res_user["name"] == "David"

# Test bad request
body = {"name": "Lato", "age": 28}
res = client.post("/users", json=body)
assert res.status_code == 422
assert len(res.json["message"]) > 0