refactor: remove legacy user registration from auth_service
- Remove unused register_user() method and helper methods - Remove legacy UserRegister schema (customer registration uses CustomerService) - Remove wrapper methods that just delegated to auth_manager - Simplify auth_service to focus on login and vendor access control - Clean up tests to match simplified service The only registration path is now /api/v1/shop/auth/register for customers, which uses CustomerService.register_customer(). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,101 +6,11 @@ from pydantic import ValidationError
|
||||
from models.schema.auth import (
|
||||
UserCreate,
|
||||
UserLogin,
|
||||
UserRegister,
|
||||
UserResponse,
|
||||
UserUpdate,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.schema
|
||||
class TestUserRegisterSchema:
|
||||
"""Test UserRegister schema validation."""
|
||||
|
||||
def test_valid_registration(self):
|
||||
"""Test valid registration data."""
|
||||
user = UserRegister(
|
||||
email="test@example.com",
|
||||
username="testuser",
|
||||
password="password123",
|
||||
)
|
||||
assert user.email == "test@example.com"
|
||||
assert user.username == "testuser"
|
||||
assert user.password == "password123"
|
||||
|
||||
def test_username_normalized_to_lowercase(self):
|
||||
"""Test username is normalized to lowercase."""
|
||||
user = UserRegister(
|
||||
email="test@example.com",
|
||||
username="TestUser",
|
||||
password="password123",
|
||||
)
|
||||
assert user.username == "testuser"
|
||||
|
||||
def test_username_with_whitespace_invalid(self):
|
||||
"""Test username with whitespace is invalid (validation before strip)."""
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
UserRegister(
|
||||
email="test@example.com",
|
||||
username=" testuser ",
|
||||
password="password123",
|
||||
)
|
||||
assert "username" in str(exc_info.value).lower()
|
||||
|
||||
def test_invalid_email(self):
|
||||
"""Test invalid email raises ValidationError."""
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
UserRegister(
|
||||
email="not-an-email",
|
||||
username="testuser",
|
||||
password="password123",
|
||||
)
|
||||
assert "email" in str(exc_info.value).lower()
|
||||
|
||||
def test_invalid_username_special_chars(self):
|
||||
"""Test username with special characters raises ValidationError."""
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
UserRegister(
|
||||
email="test@example.com",
|
||||
username="test@user!",
|
||||
password="password123",
|
||||
)
|
||||
assert "username" in str(exc_info.value).lower()
|
||||
|
||||
def test_valid_username_with_underscore(self):
|
||||
"""Test username with underscore is valid."""
|
||||
user = UserRegister(
|
||||
email="test@example.com",
|
||||
username="test_user_123",
|
||||
password="password123",
|
||||
)
|
||||
assert user.username == "test_user_123"
|
||||
|
||||
def test_password_too_short(self):
|
||||
"""Test password shorter than 6 characters raises ValidationError."""
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
UserRegister(
|
||||
email="test@example.com",
|
||||
username="testuser",
|
||||
password="12345",
|
||||
)
|
||||
assert "password" in str(exc_info.value).lower()
|
||||
|
||||
def test_password_exactly_6_chars(self):
|
||||
"""Test password with exactly 6 characters is valid."""
|
||||
user = UserRegister(
|
||||
email="test@example.com",
|
||||
username="testuser",
|
||||
password="123456",
|
||||
)
|
||||
assert user.password == "123456"
|
||||
|
||||
def test_missing_required_fields(self):
|
||||
"""Test missing required fields raises ValidationError."""
|
||||
with pytest.raises(ValidationError):
|
||||
UserRegister(email="test@example.com")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.schema
|
||||
class TestUserLoginSchema:
|
||||
|
||||
Reference in New Issue
Block a user