@@ -52,8 +52,9 @@ def mock_settings() -> MagicMock:
5252
5353
5454@pytest .fixture
55- def mock_token_file (tmp_path ) -> Path :
55+ def mock_token_file (tmp_path , record_property ) -> Path :
5656 """Create a temporary token file for testing."""
57+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
5758 return tmp_path / "token" # Return directly, no need for assignment
5859
5960
@@ -107,8 +108,9 @@ class TestGetToken:
107108 """Test cases for the get_token function."""
108109
109110 @staticmethod
110- def test_get_token_from_cache_valid (mock_settings , valid_token_with_expiry ) -> None :
111+ def test_get_token_from_cache_valid (record_property , mock_settings , valid_token_with_expiry ) -> None :
111112 """Test retrieving a valid token from cache."""
113+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
112114 # Create a mock for Path that can be properly asserted on
113115 mock_write_text = MagicMock ()
114116
@@ -123,8 +125,9 @@ def test_get_token_from_cache_valid(mock_settings, valid_token_with_expiry) -> N
123125 mock_write_text .assert_not_called ()
124126
125127 @staticmethod
126- def test_get_token_from_cache_expired (mock_settings , expired_token ) -> None :
128+ def test_get_token_from_cache_expired (record_property , mock_settings , expired_token ) -> None :
127129 """Test retrieving an expired token from cache, which should trigger re-authentication."""
130+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
128131 # Create a mock for Path that can be properly asserted on
129132 mock_write_text = MagicMock ()
130133
@@ -144,8 +147,9 @@ def test_get_token_from_cache_expired(mock_settings, expired_token) -> None:
144147 assert mock_write_text .call_count == 1
145148
146149 @staticmethod
147- def test_get_token_no_cache (mock_settings ) -> None :
150+ def test_get_token_no_cache (record_property , mock_settings ) -> None :
148151 """Test retrieving a token without using cache."""
152+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
149153 # Create a mock for Path that can be properly asserted on
150154 mock_write_text = MagicMock ()
151155
@@ -163,8 +167,9 @@ def test_get_token_no_cache(mock_settings) -> None:
163167 mock_write_text .assert_not_called ()
164168
165169 @staticmethod
166- def test_authenticate_uses_refresh_token_when_available (mock_settings ) -> None :
170+ def test_authenticate_uses_refresh_token_when_available (record_property , mock_settings ) -> None :
167171 """Test that _authenticate uses refresh token flow when refresh token is available."""
172+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
168173 # Set up refresh token in settings
169174 mock_settings .return_value .refresh_token = SecretStr ("test-refresh-token" )
170175
@@ -176,8 +181,9 @@ def test_authenticate_uses_refresh_token_when_available(mock_settings) -> None:
176181 mock_refresh .assert_called_once_with (mock_settings .return_value .refresh_token )
177182
178183 @staticmethod
179- def test_authenticate_uses_browser_flow_when_available (mock_settings ) -> None :
184+ def test_authenticate_uses_browser_flow_when_available (record_property , mock_settings ) -> None :
180185 """Test that _authenticate uses browser flow when browser is available."""
186+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
181187 mock_settings .return_value .refresh_token = None
182188
183189 with (
@@ -192,8 +198,9 @@ def test_authenticate_uses_browser_flow_when_available(mock_settings) -> None:
192198 mock_browser .assert_called_once ()
193199
194200 @staticmethod
195- def test_authenticate_falls_back_to_device_flow (mock_settings ) -> None :
201+ def test_authenticate_falls_back_to_device_flow (record_property , mock_settings ) -> None :
196202 """Test that _authenticate falls back to device flow when browser and refresh token are unavailable."""
203+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
197204 mock_settings .return_value .refresh_token = None
198205
199206 with (
@@ -207,8 +214,9 @@ def test_authenticate_falls_back_to_device_flow(mock_settings) -> None:
207214 mock_device .assert_called_once ()
208215
209216 @staticmethod
210- def test_authenticate_raises_error_on_failure (mock_settings ) -> None :
217+ def test_authenticate_raises_error_on_failure (record_property , mock_settings ) -> None :
211218 """Test that _authenticate raises an error when all authentication methods fail."""
219+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
212220 mock_settings .return_value .refresh_token = None
213221
214222 with (
@@ -223,8 +231,9 @@ class TestVerifyAndDecodeToken:
223231 """Test cases for the verify_and_decode_token function."""
224232
225233 @staticmethod
226- def test_verify_and_decode_valid_token () -> None :
234+ def test_verify_and_decode_valid_token (record_property ) -> None :
227235 """Test that a valid token is properly verified and decoded."""
236+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
228237 mock_jwt_client = MagicMock ()
229238 mock_signing_key = MagicMock ()
230239 mock_signing_key .key = "test-key"
@@ -240,8 +249,9 @@ def test_verify_and_decode_valid_token() -> None:
240249 assert "exp" in result
241250
242251 @staticmethod
243- def test_verify_and_decode_invalid_token () -> None :
252+ def test_verify_and_decode_invalid_token (record_property ) -> None :
244253 """Test that an invalid token raises an appropriate error."""
254+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
245255 with (
246256 patch ("jwt.PyJWKClient" ),
247257 patch ("jwt.get_unverified_header" ),
@@ -255,8 +265,9 @@ class TestBrowserCapabilityCheck:
255265 """Test cases for the browser capability check functionality."""
256266
257267 @staticmethod
258- def test_can_open_browser_true () -> None :
268+ def test_can_open_browser_true (record_property ) -> None :
259269 """Test that _can_open_browser returns True when a browser is available."""
270+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
260271 # We need to override the autouse fixture here
261272 with (
262273 patch ("webbrowser.get" , return_value = MagicMock ()),
@@ -265,8 +276,9 @@ def test_can_open_browser_true() -> None:
265276 assert _can_open_browser () is True
266277
267278 @staticmethod
268- def test_can_open_browser_false () -> None :
279+ def test_can_open_browser_false (record_property ) -> None :
269280 """Test that _can_open_browser returns False when no browser is available."""
281+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
270282 with patch ("webbrowser.get" , side_effect = webbrowser .Error ):
271283 assert _can_open_browser () is False
272284
@@ -275,8 +287,9 @@ class TestAuthorizationCodeFlow:
275287 """Test cases for the authorization code flow with PKCE."""
276288
277289 @staticmethod
278- def test_perform_authorization_code_flow_success (mock_settings ) -> None :
290+ def test_perform_authorization_code_flow_success (record_property , mock_settings ) -> None :
279291 """Test successful authorization code flow with PKCE."""
292+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
280293 # Mock OAuth session
281294 mock_session = MagicMock (spec = OAuth2Session )
282295 mock_session .authorization_url .return_value = ("https://test.auth/authorize?code_challenge=abc" , None )
@@ -328,8 +341,9 @@ def handle_request_side_effect():
328341 mock_session .authorization_url .assert_called_once ()
329342
330343 @staticmethod
331- def test_perform_authorization_code_flow_invalid_redirect (mock_settings ) -> None :
344+ def test_perform_authorization_code_flow_invalid_redirect (record_property , mock_settings ) -> None :
332345 """Test authorization code flow fails with invalid redirect URI."""
346+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
333347 # Mock OAuth session to prevent it from being created
334348 mock_session = MagicMock (spec = OAuth2Session )
335349 mock_session .authorization_url .return_value = ("https://test.auth/authorize?code_challenge=abc" , None )
@@ -347,8 +361,9 @@ def test_perform_authorization_code_flow_invalid_redirect(mock_settings) -> None
347361 _perform_authorization_code_with_pkce_flow ()
348362
349363 @staticmethod
350- def test_perform_authorization_code_flow_failure (mock_settings ) -> None :
364+ def test_perform_authorization_code_flow_failure (record_property , mock_settings ) -> None :
351365 """Test authorization code flow when authentication fails."""
366+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
352367 # Mock OAuth session
353368 mock_session = MagicMock (spec = OAuth2Session )
354369 mock_session .authorization_url .return_value = ("https://test.auth/authorize?code_challenge=abc" , None )
@@ -400,8 +415,9 @@ class TestDeviceFlow:
400415 """Test cases for the device flow authentication."""
401416
402417 @staticmethod
403- def test_perform_device_flow_success (mock_settings ) -> None :
418+ def test_perform_device_flow_success (record_property , mock_settings ) -> None :
404419 """Test successful device flow authentication."""
420+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
405421 device_response = {
406422 "device_code" : "device-code-123" ,
407423 "verification_uri_complete" : "https://test.auth/device/activate" ,
@@ -441,30 +457,34 @@ class TestPortAvailability:
441457 """Test cases for checking port availability."""
442458
443459 @staticmethod
444- def test_port_available () -> None :
460+ def test_port_available (record_property ) -> None :
445461 """Test that _ensure_local_port_is_available returns True when the port is available."""
462+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
446463 with patch ("socket.socket.bind" , return_value = None ) as mock_bind :
447464 assert _ensure_local_port_is_available (8000 ) is True
448465 mock_bind .assert_called_once ()
449466
450467 @staticmethod
451- def test_port_unavailable () -> None :
468+ def test_port_unavailable (record_property ) -> None :
452469 """Test that _ensure_local_port_is_available returns False when the port is unavailable."""
470+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
453471 with patch ("socket.socket.bind" , side_effect = socket .error ) as mock_bind :
454472 assert _ensure_local_port_is_available (8000 ) is False
455473 mock_bind .assert_called ()
456474
457475 @staticmethod
458- def test_port_retries () -> None :
476+ def test_port_retries (record_property ) -> None :
459477 """Test that _ensure_local_port_is_available retries the specified number of times."""
478+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
460479 with patch ("socket.socket.bind" , side_effect = socket .error ) as mock_bind , patch ("time.sleep" ) as mock_sleep :
461480 assert _ensure_local_port_is_available (8000 , max_retries = 3 ) is False
462481 assert mock_bind .call_count == 4 # Initial attempt + 3 retries
463482 assert mock_sleep .call_count == 3
464483
465484 @staticmethod
466- def test_port_availability_uses_socket_reuse () -> None :
485+ def test_port_availability_uses_socket_reuse (record_property ) -> None :
467486 """Test that _ensure_local_port_is_available uses SO_REUSEADDR socket option."""
487+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
468488 mock_socket = MagicMock ()
469489 # Make the mock work as a context manager
470490 mock_socket .__enter__ = MagicMock (return_value = mock_socket )
@@ -479,8 +499,9 @@ def test_port_availability_uses_socket_reuse() -> None:
479499 mock_socket .bind .assert_called_with (("localhost" , 8000 ))
480500
481501 @staticmethod
482- def test_authorization_flow_sets_socket_reuse (mock_settings ) -> None :
502+ def test_authorization_flow_sets_socket_reuse (record_property , mock_settings ) -> None :
483503 """Test that the HTTPServer in authorization flow uses SO_REUSEADDR."""
504+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
484505 mock_server = MagicMock ()
485506 mock_socket = MagicMock ()
486507 mock_server .socket = mock_socket
@@ -511,8 +532,9 @@ class TestRemoveCachedToken:
511532 """Test cases for the remove_cached_token function."""
512533
513534 @staticmethod
514- def test_remove_cached_token_exists (mock_settings ) -> None :
535+ def test_remove_cached_token_exists (record_property , mock_settings ) -> None :
515536 """Test removing a cached token when the token file exists."""
537+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
516538 with (
517539 patch .object (Path , "exists" , return_value = True ),
518540 patch .object (Path , "unlink" ) as mock_unlink ,
@@ -523,16 +545,18 @@ def test_remove_cached_token_exists(mock_settings) -> None:
523545 mock_unlink .assert_called_once_with (missing_ok = True )
524546
525547 @staticmethod
526- def test_remove_cached_token_not_exists (mock_settings ) -> None :
548+ def test_remove_cached_token_not_exists (record_property , mock_settings ) -> None :
527549 """Test removing a cached token when the token file does not exist."""
550+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
528551 with patch .object (Path , "exists" , return_value = False ):
529552 result = remove_cached_token ()
530553
531554 assert result is False
532555
533556 @staticmethod
534- def test_remove_cached_token_unlink_error (mock_settings ) -> None :
557+ def test_remove_cached_token_unlink_error (record_property , mock_settings ) -> None :
535558 """Test that remove_cached_token handles unlink errors gracefully."""
559+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
536560 with (
537561 patch .object (Path , "exists" , return_value = True ),
538562 patch .object (Path , "unlink" , side_effect = OSError ("Permission denied" )) as mock_unlink ,
@@ -546,8 +570,9 @@ class TestSentryIntegration:
546570 """Test cases for Sentry integration in the authentication module."""
547571
548572 @staticmethod
549- def test_get_token_calls_sentry_set_user (mock_settings ) -> None :
573+ def test_get_token_calls_sentry_set_user (record_property , mock_settings ) -> None :
550574 """Test that get_token calls sentry_sdk.set_user with correct user information extracted from token claims."""
575+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
551576 # Mock token claims with the required fields
552577 mock_claims = {
553578 "sub" : "user123" ,
@@ -579,8 +604,9 @@ def test_get_token_calls_sentry_set_user(mock_settings) -> None:
579604 mock_sentry_sdk .set_user .assert_called_once_with ({"id" : "user123" , "org_id" : "org456" })
580605
581606 @staticmethod
582- def test_get_token_sentry_unavailable (mock_settings ) -> None :
607+ def test_get_token_sentry_unavailable (record_property , mock_settings ) -> None :
583608 """Test that get_token works correctly when sentry_sdk is not available."""
609+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
584610 # Mock token claims
585611 mock_claims = {
586612 "sub" : "user123" ,
@@ -606,8 +632,9 @@ def test_get_token_sentry_unavailable(mock_settings) -> None:
606632 assert token == "test.token" # noqa: S105 - Test credential
607633
608634 @staticmethod
609- def test_get_token_sentry_missing_sub_claim (mock_settings ) -> None :
635+ def test_get_token_sentry_missing_sub_claim (record_property , mock_settings ) -> None :
610636 """Test that get_token handles missing 'sub' claim gracefully when informing Sentry."""
637+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
611638 # Mock token claims without 'sub' field
612639 mock_claims = {
613640 "org_id" : "org456" ,
@@ -638,8 +665,9 @@ def test_get_token_sentry_missing_sub_claim(mock_settings) -> None:
638665 mock_sentry_sdk .set_user .assert_not_called ()
639666
640667 @staticmethod
641- def test_get_token_sentry_handles_token_verification_error (mock_settings ) -> None :
668+ def test_get_token_sentry_handles_token_verification_error (record_property , mock_settings ) -> None :
642669 """Test that get_token fails when token verification fails, and Sentry is not informed."""
670+ record_property ("tested-item-id" , "SPEC-PLATFORM-SERVICE" )
643671 # Create a mock for sentry_sdk
644672 mock_sentry_sdk = MagicMock ()
645673
0 commit comments