ruff format
This commit is contained in:
parent
201c61f47f
commit
cd285d2f56
2 changed files with 29 additions and 8 deletions
|
|
@ -119,6 +119,7 @@ class TestConditionalAuthenticationEndpoints:
|
||||||
assert response.status_code != 401
|
assert response.status_code != 401
|
||||||
# Note: This test verifies conditional authentication works in the current environment
|
# Note: This test verifies conditional authentication works in the current environment
|
||||||
|
|
||||||
|
|
||||||
class TestConditionalAuthenticationBehavior:
|
class TestConditionalAuthenticationBehavior:
|
||||||
"""Test the behavior of conditional authentication across different endpoints."""
|
"""Test the behavior of conditional authentication across different endpoints."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,17 @@ class TestConditionalAuthentication:
|
||||||
"""Test cases for conditional authentication functionality."""
|
"""Test cases for conditional authentication functionality."""
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@patch("cognee.modules.users.methods.get_authenticated_user.get_default_user", new_callable=AsyncMock)
|
@patch(
|
||||||
|
"cognee.modules.users.methods.get_authenticated_user.get_default_user",
|
||||||
|
new_callable=AsyncMock,
|
||||||
|
)
|
||||||
@patch(
|
@patch(
|
||||||
"cognee.modules.users.methods.get_authenticated_user.REQUIRE_AUTHENTICATION",
|
"cognee.modules.users.methods.get_authenticated_user.REQUIRE_AUTHENTICATION",
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
async def test_require_authentication_false_no_token_returns_default_user(self, mock_get_default):
|
async def test_require_authentication_false_no_token_returns_default_user(
|
||||||
|
self, mock_get_default
|
||||||
|
):
|
||||||
"""Test that when REQUIRE_AUTHENTICATION=false and no token, returns default user."""
|
"""Test that when REQUIRE_AUTHENTICATION=false and no token, returns default user."""
|
||||||
# Mock the default user
|
# Mock the default user
|
||||||
mock_default_user = SimpleNamespace(id=uuid4(), email="default@example.com", is_active=True)
|
mock_default_user = SimpleNamespace(id=uuid4(), email="default@example.com", is_active=True)
|
||||||
|
|
@ -34,12 +39,17 @@ class TestConditionalAuthentication:
|
||||||
mock_get_default.assert_called_once()
|
mock_get_default.assert_called_once()
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@patch("cognee.modules.users.methods.get_authenticated_user.get_default_user", new_callable=AsyncMock)
|
@patch(
|
||||||
|
"cognee.modules.users.methods.get_authenticated_user.get_default_user",
|
||||||
|
new_callable=AsyncMock,
|
||||||
|
)
|
||||||
@patch(
|
@patch(
|
||||||
"cognee.modules.users.methods.get_authenticated_user.REQUIRE_AUTHENTICATION",
|
"cognee.modules.users.methods.get_authenticated_user.REQUIRE_AUTHENTICATION",
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
async def test_require_authentication_false_with_valid_user_returns_user(self, mock_get_default):
|
async def test_require_authentication_false_with_valid_user_returns_user(
|
||||||
|
self, mock_get_default
|
||||||
|
):
|
||||||
"""Test that when REQUIRE_AUTHENTICATION=false and valid user, returns that user."""
|
"""Test that when REQUIRE_AUTHENTICATION=false and valid user, returns that user."""
|
||||||
mock_authenticated_user = User(
|
mock_authenticated_user = User(
|
||||||
id=uuid4(),
|
id=uuid4(),
|
||||||
|
|
@ -82,6 +92,7 @@ class TestConditionalAuthentication:
|
||||||
|
|
||||||
assert result == mock_authenticated_user
|
assert result == mock_authenticated_user
|
||||||
|
|
||||||
|
|
||||||
class TestConditionalAuthenticationIntegration:
|
class TestConditionalAuthenticationIntegration:
|
||||||
"""Integration tests that test the full authentication flow."""
|
"""Integration tests that test the full authentication flow."""
|
||||||
|
|
||||||
|
|
@ -200,7 +211,10 @@ class TestConditionalAuthenticationEdgeCases:
|
||||||
"""Test edge cases and error scenarios."""
|
"""Test edge cases and error scenarios."""
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@patch("cognee.modules.users.methods.get_authenticated_user.get_default_user", new_callable=AsyncMock)
|
@patch(
|
||||||
|
"cognee.modules.users.methods.get_authenticated_user.get_default_user",
|
||||||
|
new_callable=AsyncMock,
|
||||||
|
)
|
||||||
@patch.dict(os.environ, {"REQUIRE_AUTHENTICATION": "false"})
|
@patch.dict(os.environ, {"REQUIRE_AUTHENTICATION": "false"})
|
||||||
async def test_get_default_user_raises_exception(self, mock_get_default):
|
async def test_get_default_user_raises_exception(self, mock_get_default):
|
||||||
"""Test behavior when get_default_user raises an exception."""
|
"""Test behavior when get_default_user raises an exception."""
|
||||||
|
|
@ -215,7 +229,10 @@ class TestConditionalAuthenticationEdgeCases:
|
||||||
await get_authenticated_user(user=None)
|
await get_authenticated_user(user=None)
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@patch("cognee.modules.users.methods.get_authenticated_user.get_default_user", new_callable=AsyncMock)
|
@patch(
|
||||||
|
"cognee.modules.users.methods.get_authenticated_user.get_default_user",
|
||||||
|
new_callable=AsyncMock,
|
||||||
|
)
|
||||||
@patch(
|
@patch(
|
||||||
"cognee.modules.users.methods.get_authenticated_user.REQUIRE_AUTHENTICATION",
|
"cognee.modules.users.methods.get_authenticated_user.REQUIRE_AUTHENTICATION",
|
||||||
False,
|
False,
|
||||||
|
|
@ -260,7 +277,10 @@ class TestConditionalAuthenticationEdgeCases:
|
||||||
class TestAuthenticationScenarios:
|
class TestAuthenticationScenarios:
|
||||||
"""Test specific authentication scenarios that could occur in FastAPI Users."""
|
"""Test specific authentication scenarios that could occur in FastAPI Users."""
|
||||||
|
|
||||||
@patch("cognee.modules.users.methods.get_authenticated_user.get_default_user", new_callable=AsyncMock)
|
@patch(
|
||||||
|
"cognee.modules.users.methods.get_authenticated_user.get_default_user",
|
||||||
|
new_callable=AsyncMock,
|
||||||
|
)
|
||||||
@patch(
|
@patch(
|
||||||
"cognee.modules.users.methods.get_authenticated_user.REQUIRE_AUTHENTICATION",
|
"cognee.modules.users.methods.get_authenticated_user.REQUIRE_AUTHENTICATION",
|
||||||
False,
|
False,
|
||||||
|
|
@ -278,7 +298,7 @@ class TestAuthenticationScenarios:
|
||||||
"""
|
"""
|
||||||
mock_default_user = SimpleNamespace(id=uuid4(), email="default@example.com")
|
mock_default_user = SimpleNamespace(id=uuid4(), email="default@example.com")
|
||||||
mock_get_default.return_value = mock_default_user
|
mock_get_default.return_value = mock_default_user
|
||||||
|
|
||||||
from cognee.modules.users.methods.get_authenticated_user import (
|
from cognee.modules.users.methods.get_authenticated_user import (
|
||||||
get_authenticated_user,
|
get_authenticated_user,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue