This repository has been archived by the owner on Dec 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac67637
commit 5102519
Showing
4 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ rich = "*" | |
pylint = "*" | ||
mypy = "*" | ||
pytest = "*" | ||
httpx = "*" | ||
|
||
[requires] | ||
python_version = "3.12" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
End-to-end testings for APIs. | ||
""" | ||
|
||
from fastapi.testclient import TestClient | ||
|
||
from .main import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_users_create_and_list(): | ||
""" | ||
Create valid users and make sure it returns in the users list. | ||
""" | ||
|
||
future_users = [ | ||
{ | ||
"first_name": "Parham", | ||
"last_name": "Alvani", | ||
"age": 30, | ||
}, | ||
{ | ||
"first_name": "Elahe", | ||
"last_name": "Dastan", | ||
"age": 20, | ||
}, | ||
{ | ||
"first_name": "Seyed Parham", | ||
"last_name": "Alvani", | ||
"age": 30, | ||
}, | ||
] | ||
|
||
for user in future_users: | ||
response = client.post( | ||
"/users", | ||
json=user, | ||
) | ||
assert response.status_code == 200 | ||
assert response.json() == user | ||
|
||
response = client.get("/users") | ||
assert response.status_code == 200 | ||
users = response.json() | ||
assert len(users) == len(future_users) | ||
assert users == future_users | ||
|
||
|
||
def test_users_bad_create(): | ||
""" | ||
Create a invalid user and make sure it returns error. | ||
""" | ||
|
||
for user in [ | ||
{ | ||
"first_name": "Parham1", | ||
"last_name": "Alvani", | ||
"age": 30, | ||
}, | ||
{ | ||
"first_name": "Parham", | ||
"last_name": "Alvani", | ||
"age": -30, | ||
}, | ||
]: | ||
response = client.post( | ||
"/users", | ||
json=user, | ||
) | ||
assert response.status_code == 422 |