Skip to content

Commit

Permalink
tests/unit_tests: fix tests after the upgrade
Browse files Browse the repository at this point in the history
Fix root and token endpoint tests.

Signed-off-by: Jeny Sadadia <[email protected]>
  • Loading branch information
Jeny Sadadia committed Oct 22, 2024
1 parent ea32f34 commit c08a6a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ async def mock_beanie_get_user_by_id(mocker):
return async_mock


@pytest.fixture
async def mock_beanie_user_update(mocker):
"""Mocks async call to external method to update user"""
async_mock = AsyncMock()
mocker.patch('fastapi_users_db_beanie.BeanieUserDatabase.update',
side_effect=async_mock)
return async_mock


@pytest.fixture
def mock_auth_current_user(mocker):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_root_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ def test_root_endpoint(test_client):
HTTP Response Code 200 OK
JSON with 'message' key
"""
response = test_client.get("/latest")
response = test_client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "KernelCI API"}
5 changes: 4 additions & 1 deletion tests/unit_tests/test_token_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@


@pytest.mark.asyncio
async def test_token_endpoint(test_async_client, mock_user_find):
async def test_token_endpoint(test_async_client, mock_user_find,
mock_beanie_user_update):
"""
Test Case : Test KernelCI API /user/login endpoint
Expected Result :
Expand All @@ -34,6 +35,8 @@ async def test_token_endpoint(test_async_client, mock_user_find):
is_verified=True
)
mock_user_find.return_value = user
mock_beanie_user_update.return_value = user

response = await test_async_client.post(
"user/login",
headers={
Expand Down

0 comments on commit c08a6a2

Please sign in to comment.