Refactor tests for improved consistency and readability
- Updated test cases in `test_auth_endpoints.py` to ensure consistent formatting and style. - Enhanced `test_socket_endpoints.py` with consistent parameter formatting and improved readability. - Cleaned up `conftest.py` by ensuring consistent parameter formatting in fixtures. - Added comprehensive tests for API token dependencies in `test_api_token_dependencies.py`. - Refactored `test_auth_service.py` to maintain consistent parameter formatting. - Cleaned up `test_oauth_service.py` by removing unnecessary imports. - Improved `test_socket_service.py` with consistent formatting and readability. - Enhanced `test_cookies.py` by ensuring consistent formatting and readability. - Introduced new tests for token utilities in `test_token_utils.py` to validate token generation and expiration logic.
This commit is contained in:
@@ -73,7 +73,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_register_duplicate_email(
|
||||
self, test_client: AsyncClient, test_user: User
|
||||
self, test_client: AsyncClient, test_user: User,
|
||||
) -> None:
|
||||
"""Test registration with duplicate email."""
|
||||
user_data = {
|
||||
@@ -118,7 +118,7 @@ class TestAuthEndpoints:
|
||||
async def test_register_missing_fields(self, test_client: AsyncClient) -> None:
|
||||
"""Test registration with missing fields."""
|
||||
user_data = {
|
||||
"email": "test@example.com"
|
||||
"email": "test@example.com",
|
||||
# Missing password and name
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_success(
|
||||
self, test_client: AsyncClient, test_user: User, test_login_data: dict[str, str]
|
||||
self, test_client: AsyncClient, test_user: User, test_login_data: dict[str, str],
|
||||
) -> None:
|
||||
"""Test successful user login."""
|
||||
response = await test_client.post("/api/v1/auth/login", json=test_login_data)
|
||||
@@ -161,7 +161,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_invalid_password(
|
||||
self, test_client: AsyncClient, test_user: User
|
||||
self, test_client: AsyncClient, test_user: User,
|
||||
) -> None:
|
||||
"""Test login with invalid password."""
|
||||
login_data = {"email": test_user.email, "password": "wrongpassword"}
|
||||
@@ -183,7 +183,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_success(
|
||||
self, test_client: AsyncClient, test_user: User, auth_cookies: dict[str, str]
|
||||
self, test_client: AsyncClient, test_user: User, auth_cookies: dict[str, str],
|
||||
) -> None:
|
||||
"""Test getting current user info successfully."""
|
||||
# Set cookies on client instance to avoid deprecation warning
|
||||
@@ -210,7 +210,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_invalid_token(
|
||||
self, test_client: AsyncClient
|
||||
self, test_client: AsyncClient,
|
||||
) -> None:
|
||||
"""Test getting current user with invalid token."""
|
||||
# Set invalid cookies on client instance
|
||||
@@ -223,7 +223,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_expired_token(
|
||||
self, test_client: AsyncClient, test_user: User
|
||||
self, test_client: AsyncClient, test_user: User,
|
||||
) -> None:
|
||||
"""Test getting current user with expired token."""
|
||||
from datetime import timedelta
|
||||
@@ -237,7 +237,7 @@ class TestAuthEndpoints:
|
||||
"role": "user",
|
||||
}
|
||||
expired_token = JWTUtils.create_access_token(
|
||||
token_data, expires_delta=timedelta(seconds=-1)
|
||||
token_data, expires_delta=timedelta(seconds=-1),
|
||||
)
|
||||
|
||||
# Set expired cookies on client instance
|
||||
@@ -262,7 +262,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_access_with_user_role(
|
||||
self, test_client: AsyncClient, auth_cookies: dict[str, str]
|
||||
self, test_client: AsyncClient, auth_cookies: dict[str, str],
|
||||
) -> None:
|
||||
"""Test that regular users cannot access admin endpoints."""
|
||||
# This test would be for admin-only endpoints when they're created
|
||||
@@ -293,7 +293,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_access_with_admin_role(
|
||||
self, test_client: AsyncClient, admin_cookies: dict[str, str]
|
||||
self, test_client: AsyncClient, admin_cookies: dict[str, str],
|
||||
) -> None:
|
||||
"""Test that admin users can access admin endpoints."""
|
||||
from app.core.dependencies import get_admin_user
|
||||
@@ -357,7 +357,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_oauth_authorize_invalid_provider(
|
||||
self, test_client: AsyncClient
|
||||
self, test_client: AsyncClient,
|
||||
) -> None:
|
||||
"""Test OAuth authorization with invalid provider."""
|
||||
response = await test_client.get("/api/v1/auth/invalid/authorize")
|
||||
@@ -368,7 +368,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_oauth_callback_new_user(
|
||||
self, test_client: AsyncClient, ensure_plans: tuple[Any, Any]
|
||||
self, test_client: AsyncClient, ensure_plans: tuple[Any, Any],
|
||||
) -> None:
|
||||
"""Test OAuth callback for new user creation."""
|
||||
# Mock OAuth user info
|
||||
@@ -400,7 +400,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_oauth_callback_existing_user_link(
|
||||
self, test_client: AsyncClient, test_user: Any, ensure_plans: tuple[Any, Any]
|
||||
self, test_client: AsyncClient, test_user: Any, ensure_plans: tuple[Any, Any],
|
||||
) -> None:
|
||||
"""Test OAuth callback for linking to existing user."""
|
||||
# Mock OAuth user info with same email as test user
|
||||
@@ -442,7 +442,7 @@ class TestAuthEndpoints:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_oauth_callback_invalid_provider(
|
||||
self, test_client: AsyncClient
|
||||
self, test_client: AsyncClient,
|
||||
) -> None:
|
||||
"""Test OAuth callback with invalid provider."""
|
||||
response = await test_client.get(
|
||||
|
||||
Reference in New Issue
Block a user