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