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:
@@ -9,7 +9,6 @@ from app.models.plan import Plan
|
||||
from app.models.user import User
|
||||
from app.schemas.auth import UserLoginRequest, UserRegisterRequest
|
||||
from app.services.auth import AuthService
|
||||
from app.utils.auth import PasswordUtils
|
||||
|
||||
|
||||
class TestAuthService:
|
||||
@@ -49,11 +48,11 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_register_duplicate_email(
|
||||
self, auth_service: AuthService, test_user: User
|
||||
self, auth_service: AuthService, test_user: User,
|
||||
) -> None:
|
||||
"""Test registration with duplicate email."""
|
||||
request = UserRegisterRequest(
|
||||
email=test_user.email, password="password123", name="Another User"
|
||||
email=test_user.email, password="password123", name="Another User",
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
@@ -90,7 +89,7 @@ class TestAuthService:
|
||||
async def test_login_invalid_email(self, auth_service: AuthService) -> None:
|
||||
"""Test login with invalid email."""
|
||||
request = UserLoginRequest(
|
||||
email="nonexistent@example.com", password="password123"
|
||||
email="nonexistent@example.com", password="password123",
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
@@ -101,7 +100,7 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_invalid_password(
|
||||
self, auth_service: AuthService, test_user: User
|
||||
self, auth_service: AuthService, test_user: User,
|
||||
) -> None:
|
||||
"""Test login with invalid password."""
|
||||
request = UserLoginRequest(email=test_user.email, password="wrongpassword")
|
||||
@@ -114,7 +113,7 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_inactive_user(
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession,
|
||||
) -> None:
|
||||
"""Test login with inactive user."""
|
||||
# Store the email before deactivating
|
||||
@@ -134,7 +133,7 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_user_without_password(
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession,
|
||||
) -> None:
|
||||
"""Test login with user that has no password hash."""
|
||||
# Store the email before removing password
|
||||
@@ -154,7 +153,7 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_success(
|
||||
self, auth_service: AuthService, test_user: User
|
||||
self, auth_service: AuthService, test_user: User,
|
||||
) -> None:
|
||||
"""Test getting current user successfully."""
|
||||
user = await auth_service.get_current_user(test_user.id)
|
||||
@@ -175,7 +174,7 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_current_user_inactive(
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession,
|
||||
) -> None:
|
||||
"""Test getting current user when user is inactive."""
|
||||
# Store the user ID before deactivating
|
||||
@@ -193,7 +192,7 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_access_token(
|
||||
self, auth_service: AuthService, test_user: User
|
||||
self, auth_service: AuthService, test_user: User,
|
||||
) -> None:
|
||||
"""Test access token creation."""
|
||||
token_response = auth_service._create_access_token(test_user)
|
||||
@@ -212,7 +211,7 @@ class TestAuthService:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_user_response(
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession
|
||||
self, auth_service: AuthService, test_user: User, test_session: AsyncSession,
|
||||
) -> None:
|
||||
"""Test user response creation."""
|
||||
# Ensure plan relationship is loaded
|
||||
|
||||
Reference in New Issue
Block a user