tests: update tests with suggested changes

This commit is contained in:
Daulet Amirkhanov 2025-09-03 14:03:38 +01:00
parent aa1251b370
commit de9bb495bc
2 changed files with 4 additions and 29 deletions

View file

@ -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."""

View file

@ -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