From 644917faef537f14c99a8f64c30c6e1bc596ac15 Mon Sep 17 00:00:00 2001 From: SamRemis Date: Tue, 4 Feb 2025 16:30:39 -0500 Subject: [PATCH 01/12] Add support for protocols trait --- .../enhancement-Protocols-98789.json | 5 ++ botocore/args.py | 26 ++++++++- botocore/exceptions.py | 9 +++ botocore/model.py | 4 ++ tests/functional/test_supported_protocols.py | 56 +++++++++++++++++++ tests/unit/test_args.py | 33 +++++++++++ 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 .changes/next-release/enhancement-Protocols-98789.json create mode 100644 tests/functional/test_supported_protocols.py diff --git a/.changes/next-release/enhancement-Protocols-98789.json b/.changes/next-release/enhancement-Protocols-98789.json new file mode 100644 index 0000000000..de38135e3f --- /dev/null +++ b/.changes/next-release/enhancement-Protocols-98789.json @@ -0,0 +1,5 @@ +{ + "type": "enhancement", + "category": "Protocols", + "description": "This version of botocore adds support for using a priority ordered list of protocols to determine which protocol to use for a service" +} diff --git a/botocore/args.py b/botocore/args.py index df08dd3cc9..a787fbbb56 100644 --- a/botocore/args.py +++ b/botocore/args.py @@ -70,6 +70,16 @@ "when_required", ) +PRIORITY_ORDERED_SUPPORTED_PROTOCOLS = list( + ( + 'json', + 'rest-json', + 'rest-xml', + 'query', + 'ec2', + ) +) + class ClientArgsCreator: def __init__( @@ -210,7 +220,7 @@ def compute_client_args( scoped_config, ): service_name = service_model.endpoint_prefix - protocol = service_model.metadata['protocol'] + protocol = self._compute_protocol(service_model) parameter_validation = True if client_config and not client_config.parameter_validation: parameter_validation = False @@ -810,6 +820,20 @@ def _compute_checksum_config(self, config_kwargs): valid_options=VALID_RESPONSE_CHECKSUM_VALIDATION_CONFIG, ) + def _compute_protocol(self, service_model): + # If we don't have a protocols trait, fall back to the legacy protocol trait + if 'protocols' not in service_model.metadata: + return service_model.metadata['protocol'] + + for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS: + if protocol in service_model.protocols: + return protocol + raise botocore.exceptions.NoSupportedProtocolError( + botocore_supported_protocols=PRIORITY_ORDERED_SUPPORTED_PROTOCOLS, + service_supported_protocols=service_model.protocols, + service=service_model.service_name, + ) + def _handle_checksum_config( self, config_kwargs, diff --git a/botocore/exceptions.py b/botocore/exceptions.py index 5f2a5a1f76..9a49664bdc 100644 --- a/botocore/exceptions.py +++ b/botocore/exceptions.py @@ -823,3 +823,12 @@ class InvalidChecksumConfigError(BotoCoreError): 'Unsupported configuration value for {config_key}. ' 'Expected one of {valid_options} but got {config_value}.' ) + + +class NoSupportedProtocolError(BotoCoreError): + """Error when a service does not use any protocol we support.""" + + fmt = ( + 'Botocore supports {botocore_supported_protocols}, but service {service} only ' + 'supports {service_supported_protocols}.' + ) diff --git a/botocore/model.py b/botocore/model.py index efd15e90e7..263aa5483c 100644 --- a/botocore/model.py +++ b/botocore/model.py @@ -422,6 +422,10 @@ def api_version(self): def protocol(self): return self._get_metadata_property('protocol') + @CachedProperty + def protocols(self): + return self._get_metadata_property('protocols') + @CachedProperty def endpoint_prefix(self): return self._get_metadata_property('endpointPrefix') diff --git a/tests/functional/test_supported_protocols.py b/tests/functional/test_supported_protocols.py new file mode 100644 index 0000000000..679b143963 --- /dev/null +++ b/tests/functional/test_supported_protocols.py @@ -0,0 +1,56 @@ +# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +# ANY KIND, either express or implied. See the License for the specific +# language governing permissions and limitations under the License. +import pytest + +from botocore.args import PRIORITY_ORDERED_SUPPORTED_PROTOCOLS +from botocore.session import get_session + + +def _all_test_cases(): + session = get_session() + loader = session.get_component('data_loader') + + services = loader.list_available_services('service-2') + services_models_with_protocols = [] + services_models_without_protocols = [] + + for service in services: + service_model = session.get_service_model(service) + if 'protocols' in service_model.metadata: + services_models_with_protocols.append(service_model) + else: + services_models_without_protocols.append(service_model) + return (services_models_with_protocols, services_models_without_protocols) + + +SERVICE_MODELS_WITH_PROTOCOLS, SERVICE_MODELS_WITHOUT_PROTOCOLS = ( + _all_test_cases() +) + + +@pytest.mark.validates_models +@pytest.mark.parametrize("service", SERVICE_MODELS_WITH_PROTOCOLS) +def test_services_with_protocols_trait_have_supported_protocol(service): + service_supported_protocols = service.protocols + message = f"No protocols supported for service {service.service_name}" + assert any( + protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS + for protocol in service_supported_protocols + ), message + + +@pytest.mark.validates_models +@pytest.mark.parametrize("service", SERVICE_MODELS_WITHOUT_PROTOCOLS) +def test_services_without_protocols_trait_have_supported_protocol(service): + message = f"No protocols supported for service {service.service_name}" + assert service.protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS, message diff --git a/tests/unit/test_args.py b/tests/unit/test_args.py index 0a17523b9d..02e92f9160 100644 --- a/tests/unit/test_args.py +++ b/tests/unit/test_args.py @@ -17,6 +17,7 @@ from botocore.client import ClientEndpointBridge from botocore.config import Config from botocore.configprovider import ConfigValueStore +from botocore.exceptions import NoSupportedProtocolError from botocore.hooks import HierarchicalEmitter from botocore.model import ServiceModel from botocore.useragent import UserAgentString @@ -63,9 +64,11 @@ def _get_service_model(self, service_name=None): service_model = mock.Mock(ServiceModel) service_model.service_name = service_name service_model.endpoint_prefix = service_name + service_model.protocols = ['query'] service_model.metadata = { 'serviceFullName': 'MyService', 'protocol': 'query', + 'protocols': ['query'], } service_model.operation_names = [] return service_model @@ -106,6 +109,19 @@ def call_get_client_args(self, **override_kwargs): call_kwargs.update(**override_kwargs) return self.args_create.get_client_args(**call_kwargs) + def call_compute_client_args(self, **override_kwargs): + call_kwargs = { + 'service_model': self.service_model, + 'client_config': None, + 'endpoint_bridge': self.bridge, + 'region_name': self.region, + 'is_secure': True, + 'endpoint_url': self.endpoint_url, + 'scoped_config': {}, + } + call_kwargs.update(**override_kwargs) + return self.args_create.compute_client_args(**call_kwargs) + def assert_create_endpoint_call(self, mock_endpoint, **override_kwargs): call_kwargs = { 'endpoint_url': self.endpoint_url, @@ -679,6 +695,23 @@ def test_response_checksum_validation_invalid_client_config(self): with self.assertRaises(exceptions.InvalidChecksumConfigError): self.call_get_client_args() + def test_protocol_resolution_without_protocols_trait(self): + client_args = self.call_compute_client_args() + self.assertEqual(client_args['protocol'], 'query') + + def test_protocol_resolution_picks_highest_supported(self): + self.service_model.protocol = 'query' + self.service_model.protocols = ['query', 'json'] + client_args = self.call_compute_client_args() + self.assertEqual(client_args['protocol'], 'json') + + def test_protocol_raises_error_for_unsupported_protocol(self): + self.service_model.protocols = ['wrongprotocol'] + with self.assertRaisesRegex( + NoSupportedProtocolError, self.service_model.service_name + ): + self.call_compute_client_args() + class TestEndpointResolverBuiltins(unittest.TestCase): def setUp(self): From f8bfb284d44eff5b85edc87d28a16ce8a981ac7c Mon Sep 17 00:00:00 2001 From: SamRemis Date: Tue, 4 Feb 2025 17:28:04 -0500 Subject: [PATCH 02/12] squash me Adds a new test and changes the list to a tuple --- botocore/args.py | 14 ++++++-------- tests/unit/test_args.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/botocore/args.py b/botocore/args.py index a787fbbb56..94828bcd40 100644 --- a/botocore/args.py +++ b/botocore/args.py @@ -70,14 +70,12 @@ "when_required", ) -PRIORITY_ORDERED_SUPPORTED_PROTOCOLS = list( - ( - 'json', - 'rest-json', - 'rest-xml', - 'query', - 'ec2', - ) +PRIORITY_ORDERED_SUPPORTED_PROTOCOLS = ( + 'json', + 'rest-json', + 'rest-xml', + 'query', + 'ec2', ) diff --git a/tests/unit/test_args.py b/tests/unit/test_args.py index 02e92f9160..7028da03d8 100644 --- a/tests/unit/test_args.py +++ b/tests/unit/test_args.py @@ -14,12 +14,15 @@ import socket from botocore import args, exceptions +from botocore.args import PRIORITY_ORDERED_SUPPORTED_PROTOCOLS from botocore.client import ClientEndpointBridge from botocore.config import Config from botocore.configprovider import ConfigValueStore from botocore.exceptions import NoSupportedProtocolError from botocore.hooks import HierarchicalEmitter from botocore.model import ServiceModel +from botocore.parsers import PROTOCOL_PARSERS +from botocore.serialize import SERIALIZERS from botocore.useragent import UserAgentString from tests import get_botocore_default_config_mapping, mock, unittest @@ -940,3 +943,15 @@ def test_sdk_endpoint_legacy_set_without_builtin_data(self): legacy_endpoint_url='https://my.legacy.endpoint.com', ) self.assertEqual(bins['SDK::Endpoint'], None) + + +class TestProtocolPriorityList: + def test_all_parsers_accounted_for(self): + assert set(PRIORITY_ORDERED_SUPPORTED_PROTOCOLS) == set( + PROTOCOL_PARSERS.keys() + ) + + def test_all_serializers_accounted_for(self): + assert set(PRIORITY_ORDERED_SUPPORTED_PROTOCOLS) == set( + SERIALIZERS.keys() + ) From 5a8e1b54fbf283830f53578988e0981e076a4ad3 Mon Sep 17 00:00:00 2001 From: SamRemis Date: Tue, 4 Feb 2025 17:35:53 -0500 Subject: [PATCH 03/12] Whitespace update, test enhancement --- botocore/args.py | 1 - tests/unit/test_args.py | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/botocore/args.py b/botocore/args.py index 94828bcd40..4a78c337bc 100644 --- a/botocore/args.py +++ b/botocore/args.py @@ -822,7 +822,6 @@ def _compute_protocol(self, service_model): # If we don't have a protocols trait, fall back to the legacy protocol trait if 'protocols' not in service_model.metadata: return service_model.metadata['protocol'] - for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS: if protocol in service_model.protocols: return protocol diff --git a/tests/unit/test_args.py b/tests/unit/test_args.py index 7028da03d8..1d705a9123 100644 --- a/tests/unit/test_args.py +++ b/tests/unit/test_args.py @@ -699,6 +699,8 @@ def test_response_checksum_validation_invalid_client_config(self): self.call_get_client_args() def test_protocol_resolution_without_protocols_trait(self): + del self.service_model.protocols + del self.service_model.metadata['protocols'] client_args = self.call_compute_client_args() self.assertEqual(client_args['protocol'], 'query') From 283cda4ddb973972e0752187d63586fa5fb4507e Mon Sep 17 00:00:00 2001 From: SamRemis Date: Tue, 4 Feb 2025 17:37:33 -0500 Subject: [PATCH 04/12] Update exceptions.py --- botocore/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botocore/exceptions.py b/botocore/exceptions.py index 9a49664bdc..41fc6757e7 100644 --- a/botocore/exceptions.py +++ b/botocore/exceptions.py @@ -826,7 +826,7 @@ class InvalidChecksumConfigError(BotoCoreError): class NoSupportedProtocolError(BotoCoreError): - """Error when a service does not use any protocol we support.""" + """Error when a service does not use any protocol supported by botocore.""" fmt = ( 'Botocore supports {botocore_supported_protocols}, but service {service} only ' From 21537781e350a8c3288899192959e7cbadfa8f38 Mon Sep 17 00:00:00 2001 From: SamRemis Date: Tue, 4 Feb 2025 17:38:20 -0500 Subject: [PATCH 05/12] Update args.py --- botocore/args.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/botocore/args.py b/botocore/args.py index 4a78c337bc..693995553b 100644 --- a/botocore/args.py +++ b/botocore/args.py @@ -819,7 +819,8 @@ def _compute_checksum_config(self, config_kwargs): ) def _compute_protocol(self, service_model): - # If we don't have a protocols trait, fall back to the legacy protocol trait + # If a service does not have a `protocols trait`, fall back to the legacy + # `protocol` trait if 'protocols' not in service_model.metadata: return service_model.metadata['protocol'] for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS: From 0ff22405f4282b68378cb5749600c2e2b19affec Mon Sep 17 00:00:00 2001 From: SamRemis Date: Wed, 5 Feb 2025 11:47:38 -0500 Subject: [PATCH 06/12] Apply suggestions from code review Co-authored-by: jonathan343 <43360731+jonathan343@users.noreply.github.com> --- botocore/args.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/botocore/args.py b/botocore/args.py index 693995553b..b5d9a8752a 100644 --- a/botocore/args.py +++ b/botocore/args.py @@ -218,7 +218,7 @@ def compute_client_args( scoped_config, ): service_name = service_model.endpoint_prefix - protocol = self._compute_protocol(service_model) + protocol = self._resolve_protocol(service_model) parameter_validation = True if client_config and not client_config.parameter_validation: parameter_validation = False @@ -818,7 +818,7 @@ def _compute_checksum_config(self, config_kwargs): valid_options=VALID_RESPONSE_CHECKSUM_VALIDATION_CONFIG, ) - def _compute_protocol(self, service_model): + def _resolve_protocol(self, service_model): # If a service does not have a `protocols trait`, fall back to the legacy # `protocol` trait if 'protocols' not in service_model.metadata: From b7093166daaca5161cc23a8ea38211f52e651a63 Mon Sep 17 00:00:00 2001 From: SamRemis Date: Wed, 5 Feb 2025 11:55:19 -0500 Subject: [PATCH 07/12] Fix code comment --- botocore/args.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botocore/args.py b/botocore/args.py index b5d9a8752a..5fad09e69d 100644 --- a/botocore/args.py +++ b/botocore/args.py @@ -819,7 +819,7 @@ def _compute_checksum_config(self, config_kwargs): ) def _resolve_protocol(self, service_model): - # If a service does not have a `protocols trait`, fall back to the legacy + # If a service does not have a `protocols` trait, fall back to the legacy # `protocol` trait if 'protocols' not in service_model.metadata: return service_model.metadata['protocol'] From fed91ea52585991419dd4d7c0c1032dfab858483 Mon Sep 17 00:00:00 2001 From: SamRemis Date: Thu, 6 Feb 2025 08:24:16 -0500 Subject: [PATCH 08/12] Apply suggestions from code review Co-authored-by: Nate Prewitt --- .changes/next-release/enhancement-Protocols-98789.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/next-release/enhancement-Protocols-98789.json b/.changes/next-release/enhancement-Protocols-98789.json index de38135e3f..c06f892f02 100644 --- a/.changes/next-release/enhancement-Protocols-98789.json +++ b/.changes/next-release/enhancement-Protocols-98789.json @@ -1,5 +1,5 @@ { "type": "enhancement", "category": "Protocols", - "description": "This version of botocore adds support for using a priority ordered list of protocols to determine which protocol to use for a service" + "description": "Added support for multiple protocols within a service based on performance priority." } From 44f1c5c0d2cd584df23c9de39038e7b65f52d9da Mon Sep 17 00:00:00 2001 From: SamRemis Date: Thu, 6 Feb 2025 11:01:13 -0500 Subject: [PATCH 09/12] Updates based on PR feedback --- botocore/args.py | 23 +++++++++++++---------- botocore/exceptions.py | 2 +- tests/unit/test_args.py | 6 +++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/botocore/args.py b/botocore/args.py index 5fad09e69d..609cda1107 100644 --- a/botocore/args.py +++ b/botocore/args.py @@ -819,18 +819,21 @@ def _compute_checksum_config(self, config_kwargs): ) def _resolve_protocol(self, service_model): + # We need to ensure `protocols` exists in the metadata before attempting to + # access it directly since referencing service_model.protocols directly will + # raise an UndefinedModelAttributeError if protocols is not defined + if service_model.metadata.get('protocols'): + for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS: + if protocol in service_model.protocols: + return protocol + raise botocore.exceptions.UnsupportedServiceProtocolsError( + botocore_supported_protocols=PRIORITY_ORDERED_SUPPORTED_PROTOCOLS, + service_supported_protocols=service_model.protocols, + service=service_model.service_name, + ) # If a service does not have a `protocols` trait, fall back to the legacy # `protocol` trait - if 'protocols' not in service_model.metadata: - return service_model.metadata['protocol'] - for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS: - if protocol in service_model.protocols: - return protocol - raise botocore.exceptions.NoSupportedProtocolError( - botocore_supported_protocols=PRIORITY_ORDERED_SUPPORTED_PROTOCOLS, - service_supported_protocols=service_model.protocols, - service=service_model.service_name, - ) + return service_model.protocol def _handle_checksum_config( self, diff --git a/botocore/exceptions.py b/botocore/exceptions.py index 41fc6757e7..10a7c586d0 100644 --- a/botocore/exceptions.py +++ b/botocore/exceptions.py @@ -825,7 +825,7 @@ class InvalidChecksumConfigError(BotoCoreError): ) -class NoSupportedProtocolError(BotoCoreError): +class UnsupportedServiceProtocolsError(BotoCoreError): """Error when a service does not use any protocol supported by botocore.""" fmt = ( diff --git a/tests/unit/test_args.py b/tests/unit/test_args.py index 1d705a9123..fa93f575b4 100644 --- a/tests/unit/test_args.py +++ b/tests/unit/test_args.py @@ -18,7 +18,7 @@ from botocore.client import ClientEndpointBridge from botocore.config import Config from botocore.configprovider import ConfigValueStore -from botocore.exceptions import NoSupportedProtocolError +from botocore.exceptions import UnsupportedServiceProtocolsError from botocore.hooks import HierarchicalEmitter from botocore.model import ServiceModel from botocore.parsers import PROTOCOL_PARSERS @@ -67,10 +67,10 @@ def _get_service_model(self, service_name=None): service_model = mock.Mock(ServiceModel) service_model.service_name = service_name service_model.endpoint_prefix = service_name + service_model.protocol = 'query' service_model.protocols = ['query'] service_model.metadata = { 'serviceFullName': 'MyService', - 'protocol': 'query', 'protocols': ['query'], } service_model.operation_names = [] @@ -713,7 +713,7 @@ def test_protocol_resolution_picks_highest_supported(self): def test_protocol_raises_error_for_unsupported_protocol(self): self.service_model.protocols = ['wrongprotocol'] with self.assertRaisesRegex( - NoSupportedProtocolError, self.service_model.service_name + UnsupportedServiceProtocolsError, self.service_model.service_name ): self.call_compute_client_args() From 5b12a251ef6e24b9efb17cdda6a61e6218aea71b Mon Sep 17 00:00:00 2001 From: SamRemis Date: Mon, 10 Feb 2025 18:22:18 -0500 Subject: [PATCH 10/12] Update botocore/args.py Co-authored-by: jonathan343 <43360731+jonathan343@users.noreply.github.com> --- botocore/args.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/botocore/args.py b/botocore/args.py index 609cda1107..b391433ab4 100644 --- a/botocore/args.py +++ b/botocore/args.py @@ -820,8 +820,8 @@ def _compute_checksum_config(self, config_kwargs): def _resolve_protocol(self, service_model): # We need to ensure `protocols` exists in the metadata before attempting to - # access it directly since referencing service_model.protocols directly will - # raise an UndefinedModelAttributeError if protocols is not defined + # access it directly since referencing service_model.protocols directly will + # raise an UndefinedModelAttributeError if protocols is not defined if service_model.metadata.get('protocols'): for protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS: if protocol in service_model.protocols: From 653e5129e9f88dcd3cf896c4573347a56563412b Mon Sep 17 00:00:00 2001 From: SamRemis Date: Mon, 10 Feb 2025 20:50:14 -0500 Subject: [PATCH 11/12] Updates based on PR feedback --- tests/functional/test_supported_protocols.py | 43 +++++++++----------- tests/unit/test_args.py | 7 ++++ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/tests/functional/test_supported_protocols.py b/tests/functional/test_supported_protocols.py index 679b143963..c9e85914e5 100644 --- a/tests/functional/test_supported_protocols.py +++ b/tests/functional/test_supported_protocols.py @@ -13,35 +13,26 @@ import pytest from botocore.args import PRIORITY_ORDERED_SUPPORTED_PROTOCOLS +from botocore.loaders import Loader from botocore.session import get_session -def _all_test_cases(): +def _get_services_models_by_protocols_trait(get_models_with_protocols_trait): session = get_session() - loader = session.get_component('data_loader') - - services = loader.list_available_services('service-2') - services_models_with_protocols = [] - services_models_without_protocols = [] - - for service in services: + service_list = Loader().list_available_services('service-2') + for service in service_list: service_model = session.get_service_model(service) - if 'protocols' in service_model.metadata: - services_models_with_protocols.append(service_model) - else: - services_models_without_protocols.append(service_model) - return (services_models_with_protocols, services_models_without_protocols) - - -SERVICE_MODELS_WITH_PROTOCOLS, SERVICE_MODELS_WITHOUT_PROTOCOLS = ( - _all_test_cases() -) + if ('protocols' in service_model.metadata) == get_models_with_protocols_trait: + yield service_model @pytest.mark.validates_models -@pytest.mark.parametrize("service", SERVICE_MODELS_WITH_PROTOCOLS) +@pytest.mark.parametrize( + "service", + _get_services_models_by_protocols_trait(True), +) def test_services_with_protocols_trait_have_supported_protocol(service): - service_supported_protocols = service.protocols + service_supported_protocols = service.metadata.get('protocols', []) message = f"No protocols supported for service {service.service_name}" assert any( protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS @@ -50,7 +41,13 @@ def test_services_with_protocols_trait_have_supported_protocol(service): @pytest.mark.validates_models -@pytest.mark.parametrize("service", SERVICE_MODELS_WITHOUT_PROTOCOLS) +@pytest.mark.parametrize( + "service", + _get_services_models_by_protocols_trait(False), +) def test_services_without_protocols_trait_have_supported_protocol(service): - message = f"No protocols supported for service {service.service_name}" - assert service.protocol in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS, message + message = f"Service protocol not supported for {service.service_name}" + assert ( + service.metadata.get('protocol') + in PRIORITY_ORDERED_SUPPORTED_PROTOCOLS + ), message diff --git a/tests/unit/test_args.py b/tests/unit/test_args.py index fa93f575b4..705088f37f 100644 --- a/tests/unit/test_args.py +++ b/tests/unit/test_args.py @@ -71,6 +71,7 @@ def _get_service_model(self, service_name=None): service_model.protocols = ['query'] service_model.metadata = { 'serviceFullName': 'MyService', + 'protocol': 'query', 'protocols': ['query'], } service_model.operation_names = [] @@ -951,9 +952,15 @@ class TestProtocolPriorityList: def test_all_parsers_accounted_for(self): assert set(PRIORITY_ORDERED_SUPPORTED_PROTOCOLS) == set( PROTOCOL_PARSERS.keys() + ), ( + "The map of protocol names to parsers is out of sync with the priority " + "ordered list of protocols supported by botocore" ) def test_all_serializers_accounted_for(self): assert set(PRIORITY_ORDERED_SUPPORTED_PROTOCOLS) == set( SERIALIZERS.keys() + ), ( + "The map of protocol names to serializers is out of sync with the " + "priority ordered list of protocols supported by botocore" ) From 111e49d4ad2314ac73a654348c39096cb811613a Mon Sep 17 00:00:00 2001 From: SamRemis Date: Mon, 10 Feb 2025 21:01:09 -0500 Subject: [PATCH 12/12] Rename test variable --- tests/functional/test_supported_protocols.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_supported_protocols.py b/tests/functional/test_supported_protocols.py index c9e85914e5..d8fc8b3e76 100644 --- a/tests/functional/test_supported_protocols.py +++ b/tests/functional/test_supported_protocols.py @@ -17,12 +17,12 @@ from botocore.session import get_session -def _get_services_models_by_protocols_trait(get_models_with_protocols_trait): +def _get_services_models_by_protocols_trait(has_protocol_trait): session = get_session() service_list = Loader().list_available_services('service-2') for service in service_list: service_model = session.get_service_model(service) - if ('protocols' in service_model.metadata) == get_models_with_protocols_trait: + if ('protocols' in service_model.metadata) == has_protocol_trait: yield service_model