π OpenHands: AI-Driven Development
test: PLTF-1269 replace test_should_ naming with test_verb_noun_context convention (#14015)
aivong-openhands8f5b437d12d2
diff --git a/enterprise/tests/unit/test_auth_routes.py b/enterprise/tests/unit/test_auth_routes.pyindex 3b769f16e5..27e426d0f2 100644--- a/enterprise/tests/unit/test_auth_routes.py+++ b/enterprise/tests/unit/test_auth_routes.py@@ -1462,7 +1462,7 @@ class TestKeycloakCallbackRecaptcha:"""Tests for reCAPTCHA integration in keycloak_callback()."""@pytest.mark.asyncio- async def test_should_verify_recaptcha_and_allow_login_when_score_is_high(+ async def test_login_allows_when_recaptcha_score_is_high(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that login proceeds when reCAPTCHA score is high."""@@ -1552,7 +1552,7 @@ class TestKeycloakCallbackRecaptcha:mock_recaptcha_service.create_assessment.assert_called_once()@pytest.mark.asyncio- async def test_should_block_login_when_recaptcha_score_is_low(+ async def test_login_blocks_when_recaptcha_score_is_low(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that login is blocked and redirected when reCAPTCHA score is low."""@@ -1623,7 +1623,7 @@ class TestKeycloakCallbackRecaptcha:assert 'recaptcha_blocked=true' in result.headers['location']@pytest.mark.asyncio- async def test_should_extract_ip_from_x_forwarded_for_header(+ async def test_login_extracts_ip_from_x_forwarded_for(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that IP is extracted from X-Forwarded-For header when present."""@@ -1714,7 +1714,7 @@ class TestKeycloakCallbackRecaptcha:assert call_args[1]['user_ip'] == '192.168.1.1'@pytest.mark.asyncio- async def test_should_use_client_host_when_x_forwarded_for_missing(+ async def test_login_uses_client_host_when_x_forwarded_for_missing(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that client.host is used when X-Forwarded-For is missing."""@@ -1806,7 +1806,7 @@ class TestKeycloakCallbackRecaptcha:assert call_args[1]['user_ip'] == '192.168.1.2'@pytest.mark.asyncio- async def test_should_use_unknown_ip_when_client_is_none(+ async def test_login_uses_unknown_ip_when_client_is_none(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that 'unknown' IP is used when client is None."""@@ -1897,7 +1897,7 @@ class TestKeycloakCallbackRecaptcha:assert call_args[1]['user_ip'] == 'unknown'@pytest.mark.asyncio- async def test_should_include_email_in_assessment_when_available(+ async def test_login_includes_email_in_assessment(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that email is included in assessment when available."""@@ -1985,7 +1985,7 @@ class TestKeycloakCallbackRecaptcha:assert call_args[1]['email'] == '[email protected]'@pytest.mark.asyncio- async def test_should_skip_recaptcha_when_site_key_not_configured(+ async def test_login_skips_recaptcha_when_site_key_not_configured(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that reCAPTCHA is skipped when RECAPTCHA_SITE_KEY is not configured."""@@ -2064,7 +2064,7 @@ class TestKeycloakCallbackRecaptcha:mock_recaptcha_service.create_assessment.assert_not_called()@pytest.mark.asyncio- async def test_should_skip_recaptcha_when_token_is_missing(+ async def test_login_skips_recaptcha_when_token_is_missing(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that reCAPTCHA is skipped when token is missing from state."""@@ -2137,7 +2137,7 @@ class TestKeycloakCallbackRecaptcha:mock_recaptcha_service.create_assessment.assert_not_called()@pytest.mark.asyncio- async def test_should_fail_open_when_recaptcha_service_throws_exception(+ async def test_login_fails_open_when_recaptcha_raises(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that login proceeds (fail open) when reCAPTCHA service throws exception."""@@ -2227,7 +2227,7 @@ class TestKeycloakCallbackRecaptcha:assert len(recaptcha_error_calls) > 0@pytest.mark.asyncio- async def test_should_log_warning_when_recaptcha_blocks_user(+ async def test_login_logs_warning_when_recaptcha_blocks(self, mock_request, mock_background_tasks, create_keycloak_user_info):"""Test that warning is logged when reCAPTCHA blocks user."""diff --git a/enterprise/tests/unit/test_recaptcha_service.py b/enterprise/tests/unit/test_recaptcha_service.pyindex 11ace835c4..c8367dbaec 100644--- a/enterprise/tests/unit/test_recaptcha_service.py+++ b/enterprise/tests/unit/test_recaptcha_service.py@@ -35,7 +35,7 @@ def recaptcha_service(mock_gcp_client):class TestRecaptchaServiceHashAccountId:"""Tests for RecaptchaService.hash_account_id()."""- def test_should_hash_email_with_hmac_sha256(self, recaptcha_service):+ def test_hash_account_id_uses_hmac_sha256(self, recaptcha_service):"""Test that hash_account_id produces correct HMAC-SHA256 hash."""# Arrangeemail = '[email protected]'@@ -56,7 +56,7 @@ class TestRecaptchaServiceHashAccountId:assert result == expected_hashassert len(result) == 64 # SHA256 produces 64 hex characters- def test_should_normalize_email_to_lowercase(self, recaptcha_service):+ def test_hash_account_id_normalizes_to_lowercase(self, recaptcha_service):"""Test that hash_account_id normalizes email to lowercase."""# Arrangeemail1 = '[email protected]'@@ -69,9 +69,7 @@ class TestRecaptchaServiceHashAccountId:# Assertassert hash1 == hash2- def test_should_produce_different_hashes_for_different_emails(- self, recaptcha_service- ):+ def test_hash_account_id_produces_unique_hashes_per_email(self, recaptcha_service):"""Test that different emails produce different hashes."""# Arrangeemail1 = '[email protected]'@@ -88,7 +86,7 @@ class TestRecaptchaServiceHashAccountId:class TestRecaptchaServiceCreateAssessment:"""Tests for RecaptchaService.create_assessment()."""- def test_should_create_assessment_and_allow_when_score_is_high(+ def test_create_assessment_allows_when_score_is_high(self, recaptcha_service, mock_gcp_client):"""Test that assessment allows request when score is above threshold."""@@ -118,7 +116,7 @@ class TestRecaptchaServiceCreateAssessment:assert result.action_valid is Truemock_gcp_client.create_assessment.assert_called_once()- def test_should_block_when_score_is_below_threshold(+ def test_create_assessment_blocks_when_score_is_below_threshold(self, recaptcha_service, mock_gcp_client):"""Test that assessment blocks request when score is below threshold."""@@ -143,7 +141,7 @@ class TestRecaptchaServiceCreateAssessment:assert result.allowed is Falseassert result.score == 0.2- def test_should_block_when_token_is_invalid(+ def test_create_assessment_blocks_when_token_is_invalid(self, recaptcha_service, mock_gcp_client):"""Test that assessment blocks request when token is invalid."""@@ -168,7 +166,7 @@ class TestRecaptchaServiceCreateAssessment:assert result.allowed is Falseassert result.valid is False- def test_should_block_when_action_does_not_match(+ def test_create_assessment_blocks_when_action_does_not_match(self, recaptcha_service, mock_gcp_client):"""Test that assessment blocks request when action doesn't match."""@@ -193,7 +191,7 @@ class TestRecaptchaServiceCreateAssessment:assert result.allowed is Falseassert result.action_valid is False- def test_should_include_email_in_user_info_when_provided(+ def test_create_assessment_includes_email_in_user_info(self, recaptcha_service, mock_gcp_client):"""Test that email is included in user_info when provided."""@@ -223,7 +221,7 @@ class TestRecaptchaServiceCreateAssessment:assert len(assessment.event.user_info.user_ids) == 1assert assessment.event.user_info.user_ids[0].email == '[email protected]'- def test_should_not_include_user_info_when_email_is_none(+ def test_create_assessment_omits_user_info_when_email_is_none(self, recaptcha_service, mock_gcp_client):"""Test that user_info is not included when email is None."""@@ -255,7 +253,7 @@ class TestRecaptchaServiceCreateAssessment:# If user_info exists, verify account_id is empty (not set)assert not assessment.event.user_info.account_id- def test_should_log_assessment_details_including_name(+ def test_create_assessment_logs_assessment_details(self, recaptcha_service, mock_gcp_client):"""Test that assessment details including assessment name are logged."""@@ -290,7 +288,7 @@ class TestRecaptchaServiceCreateAssessment:assert call_kwargs[1]['extra']['action_valid'] is Trueassert call_kwargs[1]['extra']['user_ip'] == '192.168.1.1'- def test_should_log_user_id_and_email_when_provided(+ def test_create_assessment_logs_user_id_and_email(self, recaptcha_service, mock_gcp_client):"""Test that user_id and email are included in log when provided."""@@ -320,7 +318,7 @@ class TestRecaptchaServiceCreateAssessment:assert call_kwargs[1]['extra']['user_id'] == 'keycloak-user-123'assert call_kwargs[1]['extra']['email'] == '[email protected]'- def test_should_log_none_for_user_id_and_email_when_not_provided(+ def test_create_assessment_logs_none_when_user_info_absent(self, recaptcha_service, mock_gcp_client):"""Test that user_id and email are logged as None when not provided."""@@ -348,7 +346,7 @@ class TestRecaptchaServiceCreateAssessment:assert call_kwargs[1]['extra']['user_id'] is Noneassert call_kwargs[1]['extra']['email'] is None- def test_should_raise_exception_when_gcp_client_fails(+ def test_create_assessment_raises_when_gcp_client_fails(self, recaptcha_service, mock_gcp_client):"""Test that exceptions from GCP client are propagated."""