@@ -352,8 +352,8 @@ def test_push_notification_config_conversion():
352352 v03_config = types_v03 .PushNotificationConfig (
353353 id = 'c1' ,
354354 url = 'http://test.com' ,
355- token = 'tok' ,
356- authentication = v03_auth , # noqa: S106
355+ token = 'tok' , # noqa: S106
356+ authentication = v03_auth ,
357357 )
358358
359359 v10_expected = pb2_v10 .PushNotificationConfig (
@@ -507,11 +507,61 @@ def test_task_status_update_event_conversion():
507507 context_id = 'c1' ,
508508 status = v03_status ,
509509 metadata = {'m' : 'v' },
510- final = False , # final is not preserved in v1.0
510+ final = True , # final is computed based on status.state
511511 )
512512 assert v03_restored == v03_expected_restored
513513
514514
515+ def test_task_status_update_event_conversion_terminal_states ():
516+ # Test all terminal states result in final=True
517+ terminal_states = [
518+ (
519+ pb2_v10 .TaskState .TASK_STATE_COMPLETED ,
520+ types_v03 .TaskState .completed ,
521+ ),
522+ (pb2_v10 .TaskState .TASK_STATE_CANCELED , types_v03 .TaskState .canceled ),
523+ (pb2_v10 .TaskState .TASK_STATE_FAILED , types_v03 .TaskState .failed ),
524+ (pb2_v10 .TaskState .TASK_STATE_REJECTED , types_v03 .TaskState .rejected ),
525+ ]
526+
527+ for core_st , compat_st in terminal_states :
528+ v10_event = pb2_v10 .TaskStatusUpdateEvent (
529+ status = pb2_v10 .TaskStatus (state = core_st )
530+ )
531+ v03_restored = to_compat_task_status_update_event (v10_event )
532+ assert v03_restored .final is True
533+ assert v03_restored .status .state == compat_st
534+
535+ # Test non-terminal states result in final=False
536+ non_terminal_states = [
537+ (
538+ pb2_v10 .TaskState .TASK_STATE_SUBMITTED ,
539+ types_v03 .TaskState .submitted ,
540+ ),
541+ (pb2_v10 .TaskState .TASK_STATE_WORKING , types_v03 .TaskState .working ),
542+ (
543+ pb2_v10 .TaskState .TASK_STATE_INPUT_REQUIRED ,
544+ types_v03 .TaskState .input_required ,
545+ ),
546+ (
547+ pb2_v10 .TaskState .TASK_STATE_AUTH_REQUIRED ,
548+ types_v03 .TaskState .auth_required ,
549+ ),
550+ (
551+ pb2_v10 .TaskState .TASK_STATE_UNSPECIFIED ,
552+ types_v03 .TaskState .unknown ,
553+ ),
554+ ]
555+
556+ for core_st , compat_st in non_terminal_states :
557+ v10_event = pb2_v10 .TaskStatusUpdateEvent (
558+ status = pb2_v10 .TaskStatus (state = core_st )
559+ )
560+ v03_restored = to_compat_task_status_update_event (v10_event )
561+ assert v03_restored .final is False
562+ assert v03_restored .status .state == compat_st
563+
564+
515565def test_task_status_update_event_conversion_minimal ():
516566 # v03 status is required but might be constructed empty internally
517567 v10_event = pb2_v10 .TaskStatusUpdateEvent (task_id = 't1' , context_id = 'c1' )
@@ -632,16 +682,16 @@ def test_oauth_flows_conversion_auth_code():
632682def test_oauth_flows_conversion_client_credentials ():
633683 v03_flows = types_v03 .OAuthFlows (
634684 client_credentials = types_v03 .ClientCredentialsOAuthFlow (
635- token_url = 'http://token2' ,
685+ token_url = 'http://token2' , # noqa: S106
636686 scopes = {'c' : 'd' },
637- refresh_url = 'ref2' , # noqa: S106
687+ refresh_url = 'ref2' ,
638688 )
639689 )
640690 v10_expected = pb2_v10 .OAuthFlows (
641691 client_credentials = pb2_v10 .ClientCredentialsOAuthFlow (
642- token_url = 'http://token2' ,
692+ token_url = 'http://token2' , # noqa: S106
643693 scopes = {'c' : 'd' },
644- refresh_url = 'ref2' , # noqa: S106
694+ refresh_url = 'ref2' ,
645695 )
646696 )
647697 v10_flows = to_core_oauth_flows (v03_flows )
@@ -674,16 +724,16 @@ def test_oauth_flows_conversion_implicit():
674724def test_oauth_flows_conversion_password ():
675725 v03_flows = types_v03 .OAuthFlows (
676726 password = types_v03 .PasswordOAuthFlow (
677- token_url = 'http://token3' ,
727+ token_url = 'http://token3' , # noqa: S106
678728 scopes = {'g' : 'h' },
679- refresh_url = 'ref4' , # noqa: S106
729+ refresh_url = 'ref4' ,
680730 )
681731 )
682732 v10_expected = pb2_v10 .OAuthFlows (
683733 password = pb2_v10 .PasswordOAuthFlow (
684- token_url = 'http://token3' ,
734+ token_url = 'http://token3' , # noqa: S106
685735 scopes = {'g' : 'h' },
686- refresh_url = 'ref4' , # noqa: S106
736+ refresh_url = 'ref4' ,
687737 )
688738 )
689739 v10_flows = to_core_oauth_flows (v03_flows )
@@ -730,8 +780,8 @@ def test_security_scheme_oauth2():
730780 v03_flows = types_v03 .OAuthFlows (
731781 authorization_code = types_v03 .AuthorizationCodeOAuthFlow (
732782 authorization_url = 'u' ,
733- token_url = 't' ,
734- scopes = {}, # noqa: S106
783+ token_url = 't' , # noqa: S106
784+ scopes = {},
735785 )
736786 )
737787 v03_scheme = types_v03 .SecurityScheme (
@@ -1161,8 +1211,8 @@ def test_task_push_notification_config_conversion():
11611211 push_notification_config = types_v03 .PushNotificationConfig (
11621212 id = 'c1' ,
11631213 url = 'http://url' ,
1164- token = 'tok' ,
1165- authentication = v03_auth , # noqa: S106
1214+ token = 'tok' , # noqa: S106
1215+ authentication = v03_auth ,
11661216 ),
11671217 )
11681218 v10_expected = pb2_v10 .TaskPushNotificationConfig (
@@ -1183,8 +1233,8 @@ def test_task_push_notification_config_conversion():
11831233 push_notification_config = types_v03 .PushNotificationConfig (
11841234 id = 'c1' ,
11851235 url = 'http://url' ,
1186- token = 'tok' ,
1187- authentication = v03_auth , # noqa: S106
1236+ token = 'tok' , # noqa: S106
1237+ authentication = v03_auth ,
11881238 ),
11891239 )
11901240 assert v03_restored == v03_expected_restored
0 commit comments