From de9bb495bce709233a8708e84e58c1f8b9c32ef5 Mon Sep 17 00:00:00 2001 From: Daulet Amirkhanov Date: Wed, 3 Sep 2025 14:03:38 +0100 Subject: [PATCH] tests: update tests with suggested changes --- ...st_conditional_authentication_endpoints.py | 29 ------------------- .../users/test_conditional_authentication.py | 4 +++ 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/cognee/tests/unit/api/test_conditional_authentication_endpoints.py b/cognee/tests/unit/api/test_conditional_authentication_endpoints.py index c066b9fa9..ef44fe637 100644 --- a/cognee/tests/unit/api/test_conditional_authentication_endpoints.py +++ b/cognee/tests/unit/api/test_conditional_authentication_endpoints.py @@ -119,35 +119,6 @@ class TestConditionalAuthenticationEndpoints: assert response.status_code != 401 # Note: This test verifies conditional authentication works in the current environment - @patch("cognee.api.v1.add.add") - @patch("cognee.modules.users.methods.get_default_user.get_default_user", new_callable=AsyncMock) - def test_authenticated_request_uses_user( - self, mock_get_default, mock_cognee_add, mock_authenticated_user - ): - """Test that authenticated requests use the authenticated user, not default user.""" - # Mock successful authentication - this would normally be handled by FastAPI Users - # but we're testing the conditional logic - mock_cognee_add.return_value = MagicMock( - model_dump=lambda: {"status": "success", "pipeline_run_id": str(uuid4())} - ) - - # Simulate authenticated request by directly testing the conditional function - from cognee.modules.users.methods.get_authenticated_user import ( - get_authenticated_user, - ) - - async def test_logic(): - # When user is provided (authenticated), should not call get_default_user - result = await get_authenticated_user(user=mock_authenticated_user) - assert result == mock_authenticated_user - mock_get_default.assert_not_called() - - # Run the async test - import asyncio - - asyncio.run(test_logic()) - - class TestConditionalAuthenticationBehavior: """Test the behavior of conditional authentication across different endpoints.""" diff --git a/cognee/tests/unit/modules/users/test_conditional_authentication.py b/cognee/tests/unit/modules/users/test_conditional_authentication.py index 51bd1eda4..c6d29c1d3 100644 --- a/cognee/tests/unit/modules/users/test_conditional_authentication.py +++ b/cognee/tests/unit/modules/users/test_conditional_authentication.py @@ -248,8 +248,12 @@ class TestConditionalAuthenticationEdgeCases: # Both should have user-like interface assert hasattr(result1, "id") assert hasattr(result1, "email") + assert result1.id == mock_user.id + assert result1.email == mock_user.email assert hasattr(result2, "id") assert hasattr(result2, "email") + assert result2.id == mock_default_user.id + assert result2.email == mock_default_user.email @pytest.mark.asyncio