示例#1
0
 def test_get_body_deserializer_unknown_content_type(self):
     """
     Test get body deserializer verifies
      that exception InvalidContentType is raised
     """
     content_type = 'application/unknown'
     deserializer = wsgi.RequestDeserializer()
     self.assertRaises(exception.InvalidContentType,
                       deserializer.get_body_deserializer, content_type)
示例#2
0
    def setUp(self):
        super(RequestDeserializerTest, self).setUp()

        class JSONDeserializer(object):
            def deserialize(self, data, action='default'):
                return 'pew_json'

        class XMLDeserializer(object):
            def deserialize(self, data, action='default'):
                return 'pew_xml'

        self.body_deserializers = {
            'application/json': JSONDeserializer(),
            'application/xml': XMLDeserializer()
        }

        self.deserializer = wsgi.RequestDeserializer(self.body_deserializers)
示例#3
0
def create_resource(version, controller_dict):
    """
    Generic function for creating a wsgi resource
    The function takes as input:
     - desired version
     - controller and metadata dictionary
       e.g.: {'1.0': [ctrl_v10, meta_v10, xml_ns],
              '1.1': [ctrl_v11, meta_v11, xml_ns]}

    """
    # the first element of the iterable is expected to be the controller
    controller = controller_dict[version][0]
    # the second element should be the metadata
    metadata = controller_dict[version][1]
    # and the third element the xml namespace
    xmlns = controller_dict[version][2]
    # and also the function for building the fault body
    fault_body_function = faults.fault_body_function(version)

    headers_serializers = {
        '1.0': HeaderSerializer10(),
        '1.1': HeaderSerializer11()
    }
    xml_serializer = wsgi.XMLDictSerializer(metadata, xmlns)
    json_serializer = wsgi.JSONDictSerializer()
    xml_deserializer = wsgi.XMLDeserializer(metadata)
    json_deserializer = wsgi.JSONDeserializer()

    body_serializers = {
        'application/xml': xml_serializer,
        'application/json': json_serializer,
    }

    body_deserializers = {
        'application/xml': xml_deserializer,
        'application/json': json_deserializer,
    }

    serializer = wsgi.ResponseSerializer(body_serializers,
                                         headers_serializers[version])
    deserializer = wsgi.RequestDeserializer(body_deserializers)

    return wsgi.Resource(controller,
                         fault_body_function,
                         deserializer,
                         serializer)