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

Fix Get Users Test & Remove Breakpoint Statement #18

Merged
merged 2 commits into from
Jun 23, 2024
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
1 change: 0 additions & 1 deletion src/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ async def check_refresh_token(refresh_token: str) -> dict[str, Any]:

forbidden_error = HTTPException(status.HTTP_401_UNAUTHORIZED)

breakpoint()
token_data = check_bearer_token(refresh_token, forbidden_error)
user_id = token_data["sub"]
token_expiration_time = dt.datetime.fromtimestamp(token_data["exp"], dt.UTC)
Expand Down
19 changes: 7 additions & 12 deletions src/tests/routers/test_users.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from beanie import PydanticObjectId
from httpx import AsyncClient
import pytest

from src.models.users import User
from src.schemas.users import UserBase
from src.schemas.users import Role, UserBase
from src.tests.routers.conftest import EMAIL, USER_INPUT


Expand Down Expand Up @@ -63,30 +64,24 @@ async def test_create_duplicate_user(test_client: AsyncClient):


@pytest.mark.asyncio
@pytest.mark.parametrize("test_user", [True], indirect=True)
@pytest.mark.parametrize("get_login_tokens", ["access"], indirect=True)
async def test_get_users(test_user, get_login_tokens, test_client: AsyncClient):
async def test_get_users(get_login_tokens, test_client: AsyncClient):
"""Tests getting list of users from the database."""

users: list[UserBase] = [test_user]

headers = {"Authorization": f"Bearer {get_login_tokens}"}
test_client.headers = headers

response = await test_client.get("/users/")
assert response.status_code == 200

response_users: list[UserBase] = response.json()["data"]["users"]
assert len(response_users) == len(users)

for i in range(len(users)):
user = users[i]
for i in range(len(response_users)):
response_user = UserBase.model_validate(response_users[i])

assert user.id == response_user.id
assert user.name == response_user.name
assert user.email == response_user.email
assert user.role == response_user.role
assert isinstance(response_user.id, PydanticObjectId)
assert response_user.name is not None and 3 <= len(response_user.name) <= 255
assert isinstance(response_user.role, Role)


@pytest.mark.asyncio
Expand Down
Loading