本文整理汇总了Python中botocore.model.ServiceModel类的典型用法代码示例。如果您正苦于以下问题:Python ServiceModel类的具体用法?Python ServiceModel怎么用?Python ServiceModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validate_ignores_response_metadata
def test_validate_ignores_response_metadata(self):
service_response = {'ResponseMetadata': {'foo': 'bar'}}
service_model = ServiceModel({
'documentation': '',
'operations': {
'foo': {
'name': 'foo',
'input': {'shape': 'StringShape'},
'output': {'shape': 'StringShape'}
}
},
'shapes': {
'StringShape': {'type': 'string'}
}
})
op_name = service_model.operation_names[0]
output_shape = service_model.operation_model(op_name).output_shape
self.client.meta.service_model = service_model
self.stubber.add_response('TestOperation', service_response)
self.validate_parameters_mock.assert_called_with(
{}, output_shape)
# Make sure service response hasn't been mutated
self.assertEqual(
service_response, {'ResponseMetadata': {'foo': 'bar'}})
示例2: TestBinaryTypes
class TestBinaryTypes(unittest.TestCase):
def setUp(self):
self.model = {
'metadata': {'protocol': 'query', 'apiVersion': '2014-01-01'},
'documentation': '',
'operations': {
'TestOperation': {
'name': 'TestOperation',
'http': {
'method': 'POST',
'requestUri': '/',
},
'input': {'shape': 'InputShape'},
}
},
'shapes': {
'InputShape': {
'type': 'structure',
'members': {
'Blob': {'shape': 'BlobType'},
}
},
'BlobType': {
'type': 'blob',
}
}
}
self.service_model = ServiceModel(self.model)
def serialize_to_request(self, input_params):
request_serializer = serialize.create_serializer(
self.service_model.metadata['protocol'])
return request_serializer.serialize_to_request(
input_params, self.service_model.operation_model('TestOperation'))
def assert_serialized_blob_equals(self, request, blob_bytes):
# This method handles all the details of the base64 decoding.
encoded = base64.b64encode(blob_bytes)
# Now the serializers actually have the base64 encoded contents
# as str types so we need to decode back. We know that this is
# ascii so it's safe to use the ascii encoding.
expected = encoded.decode('ascii')
self.assertEqual(request['body']['Blob'], expected)
def test_blob_accepts_bytes_type(self):
body = b'bytes body'
request = self.serialize_to_request(input_params={'Blob': body})
def test_blob_accepts_str_type(self):
body = u'ascii text'
request = self.serialize_to_request(input_params={'Blob': body})
self.assert_serialized_blob_equals(
request, blob_bytes=body.encode('ascii'))
def test_blob_handles_unicode_chars(self):
body = u'\u2713'
request = self.serialize_to_request(input_params={'Blob': body})
self.assert_serialized_blob_equals(
request, blob_bytes=body.encode('utf-8'))
示例3: setUp
def setUp(self):
self.model = {
'metadata': {'protocol': 'json', 'apiVersion': '2014-01-01',
'jsonVersion': '1.1', 'targetPrefix': 'foo'},
'documentation': '',
'operations': {
'TestOperation': {
'name': 'TestOperation',
'http': {
'method': 'POST',
'requestUri': '/',
},
'input': {'shape': 'InputShape'},
}
},
'shapes': {
'InputShape': {
'type': 'structure',
'members': {
'Timestamp': {'shape': 'TimestampType'},
}
},
'TimestampType': {
'type': 'timestamp',
}
}
}
self.service_model = ServiceModel(self.model)
示例4: TestCLIArgument
class TestCLIArgument(unittest.TestCase):
def setUp(self):
self.service_name = "baz"
self.service_model = ServiceModel(
{
"metadata": {"endpointPrefix": "bad"},
"operations": {"SampleOperation": {"name": "SampleOperation", "input": {"shape": "Input"}}},
"shapes": {
"StringShape": {"type": "string"},
"Input": {"type": "structure", "members": {"Foo": {"shape": "StringShape"}}},
},
},
self.service_name,
)
self.operation_model = self.service_model.operation_model("SampleOperation")
self.argument_model = self.operation_model.input_shape.members["Foo"]
self.event_emitter = mock.Mock()
def create_argument(self):
return arguments.CLIArgument(
self.argument_model.name, self.argument_model, self.operation_model, self.event_emitter
)
def test_unpack_uses_service_name_in_event(self):
self.event_emitter.emit.return_value = ["value"]
argument = self.create_argument()
params = {}
argument.add_to_params(params, "value")
expected_event_name = "process-cli-arg.%s.%s" % (self.service_name, "sample-operation")
actual_event_name = self.event_emitter.emit.call_args[0][0]
self.assertEqual(actual_event_name, expected_event_name)
示例5: TestJSONTimestampSerialization
class TestJSONTimestampSerialization(unittest.TestCase):
def setUp(self):
self.model = {
'metadata': {'protocol': 'json', 'apiVersion': '2014-01-01',
'jsonVersion': '1.1', 'targetPrefix': 'foo'},
'documentation': '',
'operations': {
'TestOperation': {
'name': 'TestOperation',
'http': {
'method': 'POST',
'requestUri': '/',
},
'input': {'shape': 'InputShape'},
}
},
'shapes': {
'InputShape': {
'type': 'structure',
'members': {
'Timestamp': {'shape': 'TimestampType'},
}
},
'TimestampType': {
'type': 'timestamp',
}
}
}
self.service_model = ServiceModel(self.model)
def serialize_to_request(self, input_params):
request_serializer = serialize.create_serializer(
self.service_model.metadata['protocol'])
return request_serializer.serialize_to_request(
input_params, self.service_model.operation_model('TestOperation'))
def test_accepts_iso_8601_format(self):
body = json.loads(self.serialize_to_request(
{'Timestamp': '1970-01-01T00:00:00'})['body'].decode('utf-8'))
self.assertEqual(body['Timestamp'], 0)
def test_accepts_epoch(self):
body = json.loads(self.serialize_to_request(
{'Timestamp': '0'})['body'].decode('utf-8'))
self.assertEqual(body['Timestamp'], 0)
# Can also be an integer 0.
body = json.loads(self.serialize_to_request(
{'Timestamp': 0})['body'].decode('utf-8'))
self.assertEqual(body['Timestamp'], 0)
def test_accepts_partial_iso_format(self):
body = json.loads(self.serialize_to_request(
{'Timestamp': '1970-01-01'})['body'].decode('utf-8'))
self.assertEqual(body['Timestamp'], 0)
示例6: test_decode_json_policy
def test_decode_json_policy(self):
parsed = {"Document": '{"foo": "foobarbaz"}', "Other": "bar"}
service_def = {
"operations": {"Foo": {"output": {"shape": "PolicyOutput"}}},
"shapes": {
"PolicyOutput": {
"type": "structure",
"members": {"Document": {"shape": "policyDocumentType"}, "Other": {"shape": "stringType"}},
},
"policyDocumentType": {"type": "string"},
"stringType": {"type": "string"},
},
}
model = ServiceModel(service_def)
op_model = model.operation_model("Foo")
handlers.json_decode_policies(parsed, op_model)
self.assertEqual(parsed["Document"], {"foo": "foobarbaz"})
no_document = {"Other": "bar"}
handlers.json_decode_policies(no_document, op_model)
self.assertEqual(no_document, {"Other": "bar"})
示例7: TestRestXMLUnicodeSerialization
class TestRestXMLUnicodeSerialization(unittest.TestCase):
def setUp(self):
self.model = {
'metadata': {'protocol': 'rest-xml', 'apiVersion': '2014-01-01'},
'documentation': '',
'operations': {
'TestOperation': {
'name': 'TestOperation',
'http': {
'method': 'POST',
'requestUri': '/',
},
'input': {'shape': 'InputShape'},
}
},
'shapes': {
'InputShape': {
'type': 'structure',
'members': {
'Foo': {
'shape': 'FooShape',
'locationName': 'Foo'
},
},
'payload': 'Foo'
},
'FooShape': {
'type': 'list',
'member': {'shape': 'StringShape'}
},
'StringShape': {
'type': 'string',
}
}
}
self.service_model = ServiceModel(self.model)
def serialize_to_request(self, input_params):
request_serializer = serialize.create_serializer(
self.service_model.metadata['protocol'])
return request_serializer.serialize_to_request(
input_params, self.service_model.operation_model('TestOperation'))
def test_restxml_serializes_unicode(self):
params = {
'Foo': [u'\u65e5\u672c\u8a9e\u3067\u304a\uff4b']
}
try:
self.serialize_to_request(params)
except UnicodeEncodeError:
self.fail("RestXML serializer failed to serialize unicode text.")
示例8: test_decode_json_policy
def test_decode_json_policy(self):
parsed = {
'Document': '{"foo": "foobarbaz"}',
'Other': 'bar',
}
service_def = {
'operations': {
'Foo': {
'output': {'shape': 'PolicyOutput'},
}
},
'shapes': {
'PolicyOutput': {
'type': 'structure',
'members': {
'Document': {
'shape': 'policyDocumentType'
},
'Other': {
'shape': 'stringType'
}
}
},
'policyDocumentType': {
'type': 'string'
},
'stringType': {
'type': 'string'
},
}
}
model = ServiceModel(service_def)
op_model = model.operation_model('Foo')
handlers.json_decode_policies(parsed, op_model)
self.assertEqual(parsed['Document'], {'foo': 'foobarbaz'})
no_document = {'Other': 'bar'}
handlers.json_decode_policies(no_document, op_model)
self.assertEqual(no_document, {'Other': 'bar'})
示例9: test_no_output
def test_no_output(self):
service_model = ServiceModel({
'operations': {
'SampleOperation': {
'name': 'SampleOperation',
'input': {'shape': 'SampleOperationInputOutput'},
}
},
'shapes': {
'SampleOperationInput': {
'type': 'structure',
'members': {}
},
'String': {
'type': 'string'
}
}
})
operation_model = service_model.operation_model('SampleOperation')
parsed = {}
self.injector.inject_attribute_value_output(
parsed=parsed, model=operation_model)
self.assertEqual(parsed, {})
示例10: setUp
def setUp(self):
self.service_name = "baz"
self.service_model = ServiceModel(
{
"metadata": {"endpointPrefix": "bad"},
"operations": {"SampleOperation": {"name": "SampleOperation", "input": {"shape": "Input"}}},
"shapes": {
"StringShape": {"type": "string"},
"Input": {"type": "structure", "members": {"Foo": {"shape": "StringShape"}}},
},
},
self.service_name,
)
self.operation_model = self.service_model.operation_model("SampleOperation")
self.argument_model = self.operation_model.input_shape.members["Foo"]
self.event_emitter = mock.Mock()
示例11: construct_manager
def construct_manager(self, cache=None, time=None, side_effect=None):
self.service_model = ServiceModel(self.service_description)
self.meta = Mock(spec=ClientMeta)
self.meta.service_model = self.service_model
self.client = Mock()
if side_effect is None:
side_effect = [{
'Endpoints': [{
'Address': 'new.com',
'CachePeriodInMinutes': 2,
}]
}]
self.client.describe_endpoints.side_effect = side_effect
self.client.meta = self.meta
self.manager = EndpointDiscoveryManager(
self.client, cache=cache, current_time=time
)
示例12: TestBinaryTypesJSON
class TestBinaryTypesJSON(unittest.TestCase):
def setUp(self):
self.model = {
'metadata': {'protocol': 'json', 'apiVersion': '2014-01-01',
'jsonVersion': '1.1', 'targetPrefix': 'foo'},
'documentation': '',
'operations': {
'TestOperation': {
'name': 'TestOperation',
'http': {
'method': 'POST',
'requestUri': '/',
},
'input': {'shape': 'InputShape'},
}
},
'shapes': {
'InputShape': {
'type': 'structure',
'members': {
'Blob': {'shape': 'BlobType'},
}
},
'BlobType': {
'type': 'blob',
}
}
}
self.service_model = ServiceModel(self.model)
def serialize_to_request(self, input_params):
request_serializer = serialize.create_serializer(
self.service_model.metadata['protocol'])
return request_serializer.serialize_to_request(
input_params, self.service_model.operation_model('TestOperation'))
def test_blob_accepts_bytes_type(self):
body = b'bytes body'
self.serialize_to_request(input_params={'Blob': body})
示例13: serialize_to_request
def serialize_to_request(self, input_params):
service_model = ServiceModel(self.model)
request_serializer = serialize.create_serializer(
service_model.metadata['protocol'])
return request_serializer.serialize_to_request(
input_params, service_model.operation_model('TestOperation'))
示例14: TestEndpointDiscoveryHandler
class TestEndpointDiscoveryHandler(BaseEndpointDiscoveryTest):
def setUp(self):
super(TestEndpointDiscoveryHandler, self).setUp()
self.manager = Mock(spec=EndpointDiscoveryManager)
self.handler = EndpointDiscoveryHandler(self.manager)
self.service_model = ServiceModel(self.service_description)
def test_register_handler(self):
events = Mock(spec=HierarchicalEmitter)
self.handler.register(events, 'foo-bar')
events.register.assert_any_call(
'before-parameter-build.foo-bar', self.handler.gather_identifiers
)
events.register.assert_any_call(
'needs-retry.foo-bar', self.handler.handle_retries
)
events.register_first.assert_called_with(
'request-created.foo-bar', self.handler.discover_endpoint
)
def test_discover_endpoint(self):
request = AWSRequest()
request.context = {
'discovery': {'identifiers': {}}
}
self.manager.describe_endpoint.return_value = 'https://new.foo'
self.handler.discover_endpoint(request, 'TestOperation')
self.assertEqual(request.url, 'https://new.foo')
self.manager.describe_endpoint.assert_called_with(
Operation='TestOperation', Identifiers={}
)
def test_discover_endpoint_fails(self):
request = AWSRequest()
request.context = {
'discovery': {'identifiers': {}}
}
request.url = 'old.com'
self.manager.describe_endpoint.return_value = None
self.handler.discover_endpoint(request, 'TestOperation')
self.assertEqual(request.url, 'old.com')
self.manager.describe_endpoint.assert_called_with(
Operation='TestOperation', Identifiers={}
)
def test_discover_endpoint_no_protocol(self):
request = AWSRequest()
request.context = {
'discovery': {'identifiers': {}}
}
self.manager.describe_endpoint.return_value = 'new.foo'
self.handler.discover_endpoint(request, 'TestOperation')
self.assertEqual(request.url, 'https://new.foo')
self.manager.describe_endpoint.assert_called_with(
Operation='TestOperation', Identifiers={}
)
def test_inject_no_context(self):
request = AWSRequest(url='https://original.foo')
self.handler.discover_endpoint(request, 'TestOperation')
self.assertEqual(request.url, 'https://original.foo')
self.manager.describe_endpoint.assert_not_called()
def test_gather_identifiers(self):
context = {}
params = {
'Foo': 'value1',
'Nested': {'Bar': 'value2'}
}
ids = {
'Foo': 'value1',
'Bar': 'value2'
}
model = self.service_model.operation_model('TestDiscoveryRequired')
self.manager.gather_identifiers.return_value = ids
self.handler.gather_identifiers(params, model, context)
self.assertEqual(context['discovery']['identifiers'], ids)
def test_gather_identifiers_not_discoverable(self):
context = {}
model = self.service_model.operation_model('DescribeEndpoints')
self.handler.gather_identifiers({}, model, context)
self.assertEqual(context, {})
def test_discovery_disabled_but_required(self):
model = self.service_model.operation_model('TestDiscoveryRequired')
with self.assertRaises(EndpointDiscoveryRequired):
block_endpoint_discovery_required_operations(model)
def test_discovery_disabled_but_optional(self):
context = {}
model = self.service_model.operation_model('TestDiscoveryOptional')
block_endpoint_discovery_required_operations(model, context=context)
self.assertEqual(context, {})
def test_does_not_retry_no_response(self):
retry = self.handler.handle_retries(None, None, None)
self.assertIsNone(retry)
def test_does_not_retry_other_errors(self):
#.........这里部分代码省略.........
示例15: setUp
def setUp(self):
super(TestEndpointDiscoveryHandler, self).setUp()
self.manager = Mock(spec=EndpointDiscoveryManager)
self.handler = EndpointDiscoveryHandler(self.manager)
self.service_model = ServiceModel(self.service_description)