From 18dee4560f1a7af1d480237f5f949cd5f5b3ab10 Mon Sep 17 00:00:00 2001 From: Dhruv <83733638+dhruv-ahuja@users.noreply.github.com> Date: Mon, 24 Jun 2024 00:40:54 +0530 Subject: [PATCH] Fix Get Users Test & Remove Breakpoint Statement (#18) * fix: remove breakpoint statement * fix: update `test_get_users` test to validate data instead of hardcoded comparisons --- src/dependencies.py | 1 - src/tests/routers/test_users.py | 19 +++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/dependencies.py b/src/dependencies.py index ee0c6c1..f3b937c 100644 --- a/src/dependencies.py +++ b/src/dependencies.py @@ -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) diff --git a/src/tests/routers/test_users.py b/src/tests/routers/test_users.py index 596fd07..0e543ea 100644 --- a/src/tests/routers/test_users.py +++ b/src/tests/routers/test_users.py @@ -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 @@ -63,13 +64,10 @@ 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 @@ -77,16 +75,13 @@ async def test_get_users(test_user, get_login_tokens, test_client: AsyncClient): 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