-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After module 9: Testing and Deployment
- Loading branch information
1 parent
a3dd928
commit c4de006
Showing
8 changed files
with
114 additions
and
10 deletions.
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
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,3 @@ | ||
[pytest] | ||
filterwarnings = | ||
ignore::sqlalchemy.exc.SAWarning |
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,44 @@ | ||
anyio==3.5.0 | ||
asgiref==3.5.0 | ||
attrs==21.4.0 | ||
bcrypt==3.2.0 | ||
certifi==2021.10.8 | ||
cffi==1.15.0 | ||
charset-normalizer==2.0.12 | ||
click==8.0.3 | ||
dnspython==2.2.0 | ||
email-validator==1.1.3 | ||
fastapi==0.73.0 | ||
h11==0.13.0 | ||
httptools==0.2.0 | ||
idna==3.3 | ||
iniconfig==1.1.1 | ||
itsdangerous==2.0.1 | ||
Jinja2==3.0.3 | ||
MarkupSafe==2.0.1 | ||
orjson==3.6.7 | ||
packaging==21.3 | ||
passlib==1.7.4 | ||
pluggy==1.0.0 | ||
py==1.11.0 | ||
pycparser==2.21 | ||
pydantic==1.9.0 | ||
pyparsing==3.0.8 | ||
python-dotenv==0.19.2 | ||
python-multipart==0.0.5 | ||
PyYAML==5.4.1 | ||
requests==2.27.1 | ||
six==1.16.0 | ||
sniffio==1.2.0 | ||
SQLAlchemy==1.4.32 | ||
sqlalchemy2-stubs==0.0.2a21 | ||
sqlmodel==0.0.6 | ||
starlette==0.17.1 | ||
tomli==2.0.1 | ||
typing_extensions==4.1.1 | ||
ujson==4.3.0 | ||
urllib3==1.26.8 | ||
uvicorn==0.15.0 | ||
uvloop==0.16.0 | ||
watchgod==0.7 | ||
websockets==10.1 |
Empty file.
Binary file not shown.
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,35 @@ | ||
from unittest.mock import Mock | ||
from fastapi.testclient import TestClient | ||
|
||
from carsharing import app | ||
from routers.cars import add_car | ||
from schemas import CarInput, User, Car | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_add_car(): | ||
response = client.post("/api/cars/", | ||
json={ | ||
"doors": 7, | ||
"size": "xxl" | ||
}, headers={'Authorization': 'Bearer reindert'} | ||
) | ||
assert response.status_code == 200 | ||
car = response.json() | ||
assert car['doors'] == 7 | ||
assert car['size'] == 'xxl' | ||
|
||
|
||
def test_add_car_with_mock_session(): | ||
mock_session = Mock() | ||
input = CarInput(doors=2, size="xl") | ||
user = User(username="reindert") | ||
result = add_car(car_input=input, session=mock_session, user=user) | ||
|
||
mock_session.add.assert_called_once() | ||
mock_session.commit.assert_called_once() | ||
mock_session.refresh.assert_called_once() | ||
assert isinstance(result, Car) | ||
assert result.doors == 2 | ||
assert result.size == "xl" |
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,14 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from carsharing import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_get_cars(): | ||
response = client.get("/api/cars/") | ||
assert response.status_code == 200 | ||
cars = response.json() | ||
assert all(["doors" in c for c in cars]) | ||
assert all(["size" in c for c in cars]) | ||
|
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,11 @@ | ||
from fastapi.testclient import TestClient | ||
|
||
from carsharing import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_home(): | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert "Welcome" in response.text |