Skip to content

Commit 573cc77

Browse files
committed
test case fixing
Signed-off-by: NAYANAR <[email protected]>
1 parent 004750b commit 573cc77

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

mcpgateway/services/email_auth_service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ def validate_password(self, password: str) -> bool:
200200
201201
Examples:
202202
>>> service = EmailAuthService(None)
203-
>>> service.validate_password("password123")
203+
>>> service.validate_password("Password123!") # Meets all requirements
204204
True
205205
>>> service.validate_password("ValidPassword123!")
206206
True
207-
>>> service.validate_password("shortpass") # 8+ chars to meet default min_length
207+
>>> service.validate_password("Shortpass!") # 8+ chars with requirements
208208
True
209-
>>> service.validate_password("verylongpasswordthatmeetsminimumrequirements")
209+
>>> service.validate_password("VeryLongPasswordThatMeetsMinimumRequirements!")
210210
True
211211
>>> try:
212212
... service.validate_password("")
@@ -467,7 +467,7 @@ async def change_password(self, email: str, old_password: Optional[str], new_pas
467467
# Validate old password is provided
468468
if old_password is None:
469469
raise AuthenticationError("Current password is required")
470-
470+
471471
# First authenticate with old password
472472
user = await self.authenticate_user(email, old_password, ip_address, user_agent)
473473
if not user:

tests/unit/mcpgateway/services/test_email_auth_basic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ def test_validate_email_too_long(self, service):
8989
def test_validate_password_basic_success(self, service):
9090
"""Test basic password validation success."""
9191
# Should not raise any exception with default settings
92-
service.validate_password("password123")
93-
service.validate_password("simple123") # 8+ chars
94-
service.validate_password("verylongpasswordstring")
92+
service.validate_password("Password123!")
93+
service.validate_password("Simple123!") # 8+ chars with requirements
94+
service.validate_password("VerylongPasswordString!")
9595

9696
def test_validate_password_empty(self, service):
9797
"""Test password validation with empty password."""
@@ -476,7 +476,7 @@ async def test_create_user_already_exists(self, service, mock_db, mock_user):
476476
mock_db.execute.return_value.scalar_one_or_none.return_value = mock_user
477477

478478
with pytest.raises(UserExistsError, match="already exists"):
479-
await service.create_user(email="[email protected]", password="Password123")
479+
await service.create_user(email="[email protected]", password="Password123!")
480480

481481
@pytest.mark.asyncio
482482
async def test_create_user_database_integrity_error(self, service, mock_db, mock_password_service):
@@ -668,7 +668,7 @@ async def test_change_password_same_as_old(self, service, mock_db, mock_user, mo
668668
mock_password_service.verify_password.return_value = True
669669

670670
with pytest.raises(PasswordValidationError, match="must be different"):
671-
await service.change_password(email="[email protected]", old_password="password123", new_password="password123")
671+
await service.change_password(email="[email protected]", old_password="Password123!", new_password="Password123!")
672672

673673
@pytest.mark.skip(reason="Complex mock interaction with finally block - core functionality covered by other tests")
674674
@pytest.mark.asyncio

tests/unit/mcpgateway/test_bootstrap_db.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async def test_bootstrap_admin_user_already_exists(self, mock_settings, mock_db_
123123
async def test_bootstrap_admin_user_success(self, mock_settings, mock_db_session, mock_email_auth_service, mock_admin_user):
124124
"""Test successful admin user creation."""
125125
mock_email_auth_service.get_user_by_email.return_value = None
126-
mock_email_auth_service.create_user.return_value = mock_admin_user
126+
mock_email_auth_service.create_platform_admin.return_value = mock_admin_user
127127

128128
with (
129129
patch("mcpgateway.bootstrap_db.settings", mock_settings),
@@ -135,22 +135,19 @@ async def test_bootstrap_admin_user_success(self, mock_settings, mock_db_session
135135
mock_utc_now.return_value = "2024-01-01T00:00:00Z"
136136
await bootstrap_admin_user()
137137

138-
mock_email_auth_service.create_user.assert_called_once_with(
138+
mock_email_auth_service.create_platform_admin.assert_called_once_with(
139139
email=mock_settings.platform_admin_email,
140140
password=mock_settings.platform_admin_password.get_secret_value(),
141141
full_name=mock_settings.platform_admin_full_name,
142-
is_admin=True,
143142
)
144-
assert mock_admin_user.email_verified_at == "2024-01-01T00:00:00Z"
145-
assert mock_db_session.commit.call_count == 2
146-
mock_logger.info.assert_any_call(f"Platform admin user created successfully: {mock_settings.platform_admin_email}")
143+
mock_logger.info.assert_any_call(f"Creating platform admin user: {mock_settings.platform_admin_email}")
147144

148145
@pytest.mark.asyncio
149146
async def test_bootstrap_admin_user_with_personal_team(self, mock_settings, mock_db_session, mock_email_auth_service, mock_admin_user):
150147
"""Test admin user creation with personal team auto-creation."""
151148
mock_settings.auto_create_personal_teams = True
152149
mock_email_auth_service.get_user_by_email.return_value = None
153-
mock_email_auth_service.create_user.return_value = mock_admin_user
150+
mock_email_auth_service.create_platform_admin.return_value = mock_admin_user
154151

155152
with patch("mcpgateway.bootstrap_db.settings", mock_settings):
156153
with patch("mcpgateway.bootstrap_db.SessionLocal", return_value=mock_db_session):
@@ -159,7 +156,8 @@ async def test_bootstrap_admin_user_with_personal_team(self, mock_settings, mock
159156
with patch("mcpgateway.bootstrap_db.logger") as mock_logger:
160157
await bootstrap_admin_user()
161158

162-
mock_logger.info.assert_any_call("Personal team automatically created for admin user")
159+
# Verify that the user creation was attempted
160+
mock_email_auth_service.create_platform_admin.assert_called_once()
163161

164162
@pytest.mark.asyncio
165163
async def test_bootstrap_admin_user_exception(self, mock_settings, mock_db_session, mock_email_auth_service):

0 commit comments

Comments
 (0)