@@ -735,3 +735,58 @@ def test_invalid_timestamp_precision_raises_error(self):
735735 timestamp_precision = 'invalid' ,
736736 )
737737 self .assertIn ("Invalid timestamp precision" , str (context .exception ))
738+
739+ class TestRpcV2CBORHostPrefix (unittest .TestCase ):
740+ def setUp (self ):
741+ self .model = {
742+ 'metadata' : {
743+ 'protocol' : 'smithy-rpc-v2-cbor' ,
744+ 'apiVersion' : '2014-01-01' ,
745+ 'serviceId' : 'MyService' ,
746+ 'targetPrefix' : 'sampleservice' ,
747+ 'documentation' : '' ,
748+ },
749+ 'operations' : {
750+ 'TestHostPrefixOperation' : {
751+ 'name' : 'TestHostPrefixOperation' ,
752+ 'input' : {'shape' : 'InputShape' },
753+ 'endpoint' : {'hostPrefix' : '{Foo}' },
754+ },
755+ 'TestNoHostPrefixOperation' : {
756+ 'name' : 'TestNoHostPrefixOperation' ,
757+ 'input' : {'shape' : 'InputShape' },
758+ },
759+ },
760+ 'shapes' : {
761+ 'InputShape' : {
762+ 'type' : 'structure' ,
763+ 'members' : {
764+ 'Foo' : {'shape' : 'StringType' , 'hostLabel' : True },
765+ },
766+ },
767+ 'StringType' : {'type' : 'string' },
768+ },
769+ }
770+ self .service_model = ServiceModel (self .model )
771+
772+ def test_host_prefix_added_to_serialized_request (self ):
773+ operation_model = self .service_model .operation_model (
774+ 'TestHostPrefixOperation'
775+ )
776+ serializer = serialize .create_serializer ('smithy-rpc-v2-cbor' )
777+
778+ params = {'Foo' : 'bound' }
779+ serialized = serializer .serialize_to_request (params , operation_model )
780+
781+ self .assertEqual (serialized ['host_prefix' ], 'bound' )
782+
783+ def test_no_host_prefix_when_not_configured (self ):
784+ operation_model = self .service_model .operation_model (
785+ 'TestNoHostPrefixOperation'
786+ )
787+ serializer = serialize .create_serializer ('smithy-rpc-v2-cbor' )
788+
789+ params = {'Foo' : 'bound' }
790+ serialized = serializer .serialize_to_request (params , operation_model )
791+
792+ self .assertNotIn ('host_prefix' , serialized )
0 commit comments