Skip to content

Commit

Permalink
Fix Get Users Test & Remove Breakpoint Statement (#18)
Browse files Browse the repository at this point in the history
* fix: remove breakpoint statement

* fix: update `test_get_users` test to validate data instead of hardcoded comparisons
  • Loading branch information
dhruv-ahuja authored Jun 23, 2024
1 parent b8c58bf commit 18dee45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
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

0 comments on commit 18dee45

Please sign in to comment.