-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add login and user tests, update gitignore
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
__pycache__ | ||
app.egg-info | ||
*.pyc | ||
coverage.xml |
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,48 @@ | ||
import pytest | ||
from fastapi import FastAPI | ||
from httpx import AsyncClient | ||
from starlette import status | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_login(client: AsyncClient, fastapi_app: FastAPI) -> None: | ||
""" | ||
Checks the health endpoint. | ||
:param client: client for the app. | ||
:param fastapi_app: current FastAPI application. | ||
""" | ||
response = await client.post( | ||
"/api/login/access-token", | ||
data={"username": "[email protected]", "password": "admin"}, | ||
) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
assert "access_token" in response.json() | ||
assert "token_type" in response.json() | ||
assert response.json()["token_type"] == "bearer" | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_token(client: AsyncClient, fastapi_app: FastAPI) -> None: | ||
""" | ||
Checks the health endpoint. | ||
:param client: client for the app. | ||
:param fastapi_app: current FastAPI application. | ||
""" | ||
|
||
response = await client.post( | ||
"/api/login/access-token", | ||
data={"username": "[email protected]", "password": "admin"}, | ||
) | ||
|
||
token = response.json()["access_token"] | ||
|
||
response = await client.post( | ||
"/api/login/test-token", | ||
headers={"Authorization": f"Bearer {token}"}, | ||
) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
assert response.json()["email"] == "[email protected]" |
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,19 @@ | ||
import pytest | ||
from fastapi import FastAPI | ||
from httpx import AsyncClient | ||
from starlette import status | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_create_user(client: AsyncClient, fastapi_app: FastAPI) -> None: | ||
""" | ||
Checks the health endpoint. | ||
:param client: client for the app. | ||
:param fastapi_app: current FastAPI application. | ||
""" | ||
response = await client.get( | ||
"/api/users/", headers={"skip": "0", "limit": "10"} | ||
) | ||
|
||
assert response.status_code == status.HTTP_401_UNAUTHORIZED |
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