From c08a6a22333d551af4fbbb4dfb63349af7be16d6 Mon Sep 17 00:00:00 2001 From: Jeny Sadadia Date: Tue, 22 Oct 2024 16:09:30 +0530 Subject: [PATCH] tests/unit_tests: fix tests after the upgrade Fix root and token endpoint tests. Signed-off-by: Jeny Sadadia --- tests/unit_tests/conftest.py | 9 +++++++++ tests/unit_tests/test_root_handler.py | 2 +- tests/unit_tests/test_token_handler.py | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index 4447b1b9..d0f7f6ab 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -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): """ diff --git a/tests/unit_tests/test_root_handler.py b/tests/unit_tests/test_root_handler.py index 295ebefc..9d0efa5b 100644 --- a/tests/unit_tests/test_root_handler.py +++ b/tests/unit_tests/test_root_handler.py @@ -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"} diff --git a/tests/unit_tests/test_token_handler.py b/tests/unit_tests/test_token_handler.py index dc5d07a3..d5753faa 100644 --- a/tests/unit_tests/test_token_handler.py +++ b/tests/unit_tests/test_token_handler.py @@ -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 : @@ -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={