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

feat: Add user email info endpoint #15

Merged
merged 2 commits into from
Aug 16, 2022
Merged
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
12 changes: 11 additions & 1 deletion src/testbench_tuna/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Union

from fastapi import FastAPI
from fastapi import FastAPI, HTTPException

from . import utils

Expand All @@ -15,3 +15,13 @@ async def get_root():
@app.get("/pizza-size")
async def get_pizza_size(diameter: Union[int, float]):
return {"area": utils.pizza_size(diameter)}


@app.get("/users/{username}/email")
async def get_users_username_email(username: str):
if username == "foo":
return {"username": username, "email": "foo@example.com"}
elif username == "bar":
return {"username": username, "email": "bar@example.com"}
else:
raise HTTPException(status_code=404, detail="User not found")
17 changes: 17 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,20 @@ def test_get_pizza_size():
response = client.get("/pizza-size", params={"diameter": 666})
assert response.status_code == 200
assert response.json() == {"area": 666}


def test_get_user_username_email_foo():
response = client.get("/users/foo/email")
assert response.status_code == 200
assert response.json() == {"username": "foo", "email": "foo@example.com"}


def test_get_user_username_email_bar():
response = client.get("/users/bar/email")
assert response.status_code == 200
assert response.json() == {"username": "bar", "email": "bar@example.com"}


def test_get_user_username_email_404():
response = client.get("/users/fefefe/email")
assert response.status_code == 404