def test_error_shapes(self):
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     # OperationName only has a NoSuchResourceException
     self.assertEqual(len(operation.error_shapes), 1)
     self.assertEqual(operation.error_shapes[0].name,
                      'NoSuchResourceException')
Пример #2
0
 def setUp(self):
     self.model = {
         'metadata': {
             'protocol': 'query',
             'endpointPrefix': 'endpoint-prefix',
             'serviceId': 'MyService'
         },
         'documentation': 'Documentation value',
         'operations': {},
         'shapes': {
             'StringShape': {
                 'type': 'string'
             }
         }
     }
     self.error_shapes = {
         'ExceptionOne': {
             'exception': True,
             'type': 'structure',
             'members': {},
         },
         'ExceptionTwo': {
             'exception': True,
             'type': 'structure',
             'members': {},
             'error': {
                 'code': 'FooCode'
             }
         },
     }
     self.service_model = model.ServiceModel(self.model)
Пример #3
0
 def test_no_output_shape(self):
     self.update_operation(output=None)
     del self.model['operations']['OperationName']['output']
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     self.assertFalse(operation.has_event_stream_output)
     self.assertEqual(operation.get_event_stream_output(), None)
Пример #4
0
 def test_shape_for_error_code(self):
     self.model['shapes'].update(self.error_shapes)
     self.service_model = model.ServiceModel(self.model)
     shape = self.service_model.shape_for_error_code('ExceptionOne')
     self.assertEqual(shape.name, 'ExceptionOne')
     shape = self.service_model.shape_for_error_code('FooCode')
     self.assertEqual(shape.name, 'ExceptionTwo')
Пример #5
0
 def test_error_shapes(self):
     self.model['shapes'].update(self.error_shapes)
     self.service_model = model.ServiceModel(self.model)
     error_shapes = self.service_model.error_shapes
     error_shape_names = [shape.name for shape in error_shapes]
     self.assertEqual(len(error_shape_names), 2)
     self.assertIn('ExceptionOne', error_shape_names)
     self.assertIn('ExceptionTwo', error_shape_names)
 def test_operation_shape_not_required(self):
     # It's ok if there's no output shape. We'll just get a return value of
     # None.
     del self.model['operations']['OperationName']['output']
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     output_shape = operation.output_shape
     self.assertIsNone(output_shape)
 def setUp(self):
     self.model = {
         'metadata': {
             'protocol': 'query',
             'endpointPrefix': 'foo'
         },
         'documentation': '',
         'operations': {
             'OperationName': {
                 'http': {
                     'method': 'POST',
                     'requestUri': '/',
                 },
                 'name': 'OperationName',
                 'input': {
                     'shape': 'OperationNameRequest'
                 },
                 'output': {
                     'shape': 'OperationNameResponse',
                 },
                 'errors': [{
                     'shape': 'NoSuchResourceException'
                 }],
                 'documentation': 'Docs for OperationName',
             }
         },
         'shapes': {
             'OperationNameRequest': {
                 'type': 'structure',
                 'members': {
                     'Arg1': {
                         'shape': 'stringType'
                     },
                     'Arg2': {
                         'shape': 'stringType'
                     },
                 }
             },
             'OperationNameResponse': {
                 'type': 'structure',
                 'members': {
                     'String': {
                         'shape': 'stringType',
                     }
                 }
             },
             'NoSuchResourceException': {
                 'type': 'structure',
                 'members': {}
             },
             'stringType': {
                 'type': 'string',
             }
         }
     }
     self.service_model = model.ServiceModel(self.model)
 def test_operation_input_model(self):
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     self.assertEqual(operation.name, 'OperationName')
     # Operations should also have a reference to the top level metadata.
     self.assertEqual(operation.metadata['protocol'], 'query')
     self.assertEqual(operation.http['method'], 'POST')
     self.assertEqual(operation.http['requestUri'], '/')
     shape = operation.input_shape
     self.assertEqual(shape.name, 'OperationNameRequest')
     self.assertEqual(list(sorted(shape.members)), ['Arg1', 'Arg2'])
 def setUp(self):
     self.model = {
         'metadata': {
             'protocol': 'query',
             'endpointPrefix': 'endpoint-prefix'
         },
         'documentation': 'Documentation value',
         'operations': {},
         'shapes': {
             'StringShape': {
                 'type': 'string'
             }
         }
     }
     self.service_model = model.ServiceModel(self.model)
Пример #10
0
 def test_service_id_does_not_exist(self):
     service_model = {
         'metadata': {
             'protocol': 'query',
             'endpointPrefix': 'endpoint-prefix',
         },
         'documentation': 'Documentation value',
         'operations': {},
         'shapes': {
             'StringShape': {
                 'type': 'string'
             }
         }
     }
     service_name = 'myservice'
     service_model = model.ServiceModel(service_model, service_name)
     with self.assertRaisesRegexp(model.UndefinedModelAttributeError,
                                  service_name):
         service_model.service_id
def test_missing_model_attribute_raises_exception():
    # We're using a nose test generator here to cut down
    # on the duplication.  The property names below
    # all have the same test logic.
    service_model = model.ServiceModel({'metadata': {'endpointPrefix': 'foo'}})
    property_names = ['api_version', 'protocol']

    def _test_attribute_raise_exception(attr_name):
        try:
            getattr(service_model, attr_name)
        except model.UndefinedModelAttributeError:
            # This is what we expect, so the test passes.
            pass
        except Exception as e:
            raise AssertionError("Expected UndefinedModelAttributeError to "
                                 "be raised, but %s was raised instead" %
                                 (e.__class__))
        else:
            raise AssertionError(
                "Expected UndefinedModelAttributeError to "
                "be raised, but no exception was raised for: %s" % attr_name)

    for name in property_names:
        yield _test_attribute_raise_exception, name
 def test_operation_output_model(self):
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     output = operation.output_shape
     self.assertEqual(list(output.members), ['String'])
     self.assertFalse(operation.has_streaming_output)
 def test_service_model_available_from_operation_model(self):
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     # This is an identity comparison because we don't implement
     # __eq__, so we may need to change this in the future.
     self.assertEqual(operation.service_model, service_model)
 def test_has_documentation_property(self):
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     self.assertEqual(operation.documentation, 'Docs for OperationName')
Пример #15
0
 def test_endpoint_discovery_present(self):
     operation = self.model['operations']['OperationName']
     operation['endpointdiscovery'] = {'required': True}
     service_model = model.ServiceModel(self.model)
     operation_name = service_model.operation_model('OperationName')
     self.assertTrue(operation_name.endpoint_discovery.get('required'))
 def test_streaming_output_for_operation(self):
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     self.assertTrue(operation.has_streaming_output)
     self.assertEqual(operation.get_streaming_output().name, 'blobType')
 def test_operation_name_in_repr(self):
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     self.assertIn('OperationName', repr(operation))
 def test_wire_name_always_matches_model(self):
     service_model = model.ServiceModel(self.model)
     operation = model.OperationModel(
         self.model['operations']['OperationName'], service_model, 'Foo')
     self.assertEqual(operation.name, 'Foo')
     self.assertEqual(operation.wire_name, 'OperationName')
Пример #19
0
 def test_deprecated_absent(self):
     service_model = model.ServiceModel(self.model)
     operation_two = service_model.operation_model('OperationTwo')
     self.assertFalse(operation_two.deprecated)
Пример #20
0
 def test_no_event_stream_output_for_operation(self):
     self.update_operation(output={'shape': 'NormalStructure'})
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     self.assertFalse(operation.has_event_stream_output)
     self.assertEqual(operation.get_event_stream_output(), None)
Пример #21
0
 def test_event_stream_output_for_operation(self):
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     self.assertTrue(operation.has_event_stream_output)
     output = operation.get_event_stream_output()
     self.assertEqual(output.name, 'EventStreamStructure')
Пример #22
0
def test_missing_model_attribute_raises_exception(property_name):
    service_model = model.ServiceModel({'metadata': {'endpointPrefix': 'foo'}})
    with pytest.raises(model.UndefinedModelAttributeError):
        getattr(service_model, property_name)
Пример #23
0
 def test_endpoint_discovery_required_no_value(self):
     operation = self.model['operations']['OperationName']
     self.assertTrue(operation.get('endpointdiscovery') is None)
     service_model = model.ServiceModel(self.model)
     self.assertFalse(service_model.endpoint_discovery_required)
Пример #24
0
 def test_deprecated_present_false(self):
     self.model['operations']['OperationName']['deprecated'] = False
     service_model = model.ServiceModel(self.model)
     operation_name = service_model.operation_model('OperationName')
     self.assertFalse(operation_name.deprecated)
 def test_not_streaming_output_for_operation(self):
     self.remove_payload('Response')
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     self.assertFalse(operation.has_streaming_output)
     self.assertEqual(operation.get_streaming_output(), None)
 def test_name_from_service(self):
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('OperationName')
     self.assertEqual(operation.name, 'OperationName')
 def test_service_name_can_be_overriden(self):
     service_model = model.ServiceModel(self.model,
                                        service_name='myservice')
     self.assertEqual(service_model.service_name, 'myservice')
 def test_name_from_service_model_when_differs_from_name(self):
     self.model['operations']['Foo'] = \
         self.model['operations']['OperationName']
     service_model = model.ServiceModel(self.model)
     operation = service_model.operation_model('Foo')
     self.assertEqual(operation.name, 'Foo')
 def test_name_and_wire_name_defaults_to_same_value(self):
     service_model = model.ServiceModel(self.model)
     operation = model.OperationModel(
         self.model['operations']['OperationName'], service_model)
     self.assertEqual(operation.name, 'OperationName')
     self.assertEqual(operation.wire_name, 'OperationName')
Пример #30
0
 def test_endpoint_operation_present_false(self):
     self.model['operations']['OperationName']['endpointoperation'] = False
     service_model = model.ServiceModel(self.model)
     operation_name = service_model.operation_model('OperationName')
     self.assertFalse(operation_name.is_endpoint_discovery_operation)