test: update service tests for fixture and API changes

Updates to work with refactored fixtures (no expunge):
- Re-query entities when modifying state in tests
- Remove assertions on expunged object properties

Auth service tests:
- Update to use email_or_username field instead of username

Admin service tests:
- Fix statistics test to use stats_service module
- Remove vendor_name filter test (field removed)
- Update import job assertions

Inventory/Marketplace/Stats/Vendor service tests:
- Refactor to work with attached session objects
- Update assertions for changed response formats
- Improve test isolation and cleanup

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-05 21:42:52 +01:00
parent ca9f17fc37
commit 120d8196fe
7 changed files with 1488 additions and 1422 deletions

View File

@@ -72,7 +72,7 @@ class TestAuthService:
def test_login_user_success(self, db, test_user):
"""Test successful user login"""
user_credentials = UserLogin(
username=test_user.username, password="testpass123"
email_or_username=test_user.username, password="testpass123"
)
result = self.service.login_user(db, user_credentials)
@@ -87,7 +87,9 @@ class TestAuthService:
def test_login_user_wrong_username(self, db):
"""Test login fails with wrong username"""
user_credentials = UserLogin(username="nonexistentuser", password="testpass123")
user_credentials = UserLogin(
email_or_username="nonexistentuser", password="testpass123"
)
with pytest.raises(InvalidCredentialsException) as exc_info:
self.service.login_user(db, user_credentials)
@@ -100,7 +102,7 @@ class TestAuthService:
def test_login_user_wrong_password(self, db, test_user):
"""Test login fails with wrong password"""
user_credentials = UserLogin(
username=test_user.username, password="wrongpassword"
email_or_username=test_user.username, password="wrongpassword"
)
with pytest.raises(InvalidCredentialsException) as exc_info:
@@ -113,12 +115,15 @@ class TestAuthService:
def test_login_user_inactive_user(self, db, test_user):
"""Test login fails for inactive user"""
# Deactivate user
test_user.is_active = False
from models.database.user import User
# Re-query user and deactivate
user = db.query(User).filter(User.id == test_user.id).first()
user.is_active = False
db.commit()
user_credentials = UserLogin(
username=test_user.username, password="testpass123"
email_or_username=test_user.username, password="testpass123"
)
with pytest.raises(UserNotActiveException) as exc_info:
@@ -130,7 +135,7 @@ class TestAuthService:
assert "User account is not active" in exception.message
# Reactivate for cleanup
test_user.is_active = True
user.is_active = True
db.commit()
def test_get_user_by_email(self, db, test_user):
@@ -285,7 +290,9 @@ class TestAuthService:
def test_login_user_database_error(self, db_with_error):
"""Test user login handles database errors"""
user_credentials = UserLogin(username="testuser", password="password123")
user_credentials = UserLogin(
email_or_username="testuser", password="password123"
)
with pytest.raises(InvalidCredentialsException):
self.service.login_user(db_with_error, user_credentials)