Removing XML serialization code

The classes no longer exists in neutron upstream. RM11046
This commit is contained in:
Josh Conant
2015-03-19 15:17:40 +00:00
parent b3022e0c01
commit f9794b521f
4 changed files with 46 additions and 14 deletions

View File

@@ -14,7 +14,6 @@
# limitations under the License.
from neutron.api import extensions
from neutron.api.v2 import attributes
from neutron import manager
from neutron import wsgi
@@ -36,23 +35,12 @@ class QuarkPortsUpdateHandler(object):
self._plugin = plugin
def handle(self, request, response):
xml_deserializer = wsgi.XMLDeserializer(attributes.get_attr_metadata())
deserializers = {'application/xml': xml_deserializer,
'application/json': wsgi.JSONDeserializer()}
xml_serializer = wsgi.XMLDictSerializer(attributes.get_attr_metadata())
serializers = {'application/xml': xml_serializer,
'application/json': wsgi.JSONDictSerializer()}
format_types = {'xml': 'application/xml',
'json': 'application/json'}
deserializer = wsgi.JSONDeserializer()
serializer = wsgi.JSONDictSerializer()
path = [part for part in request.path_url.split("/") if part]
id = path[-1].split('.')[0]
content_type = format_types.get(None,
request.best_match_content_type())
deserializer = deserializers.get(content_type)
serializer = serializers.get(content_type)
body = None
if request.body:
body = deserializer.deserialize(request.body)['body']

View File

View File

View File

@@ -0,0 +1,44 @@
# Copyright 2015 Openstack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
import mock
from oslo_log import log as logging
from quark.api.extensions import ports_quark
from quark.tests.functional.base import BaseFunctionalTest
LOG = logging.getLogger(__name__)
class TestAPIExtensionPortsQuark(BaseFunctionalTest):
def test_QuarkPortsUpdateHandler(self):
mock_plugin = mock.MagicMock()
mock_request = mock.MagicMock()
mock_response = mock.MagicMock()
body = '"lots of stuff"'
port_id = "I_am_a_port"
handler = ports_quark.QuarkPortsUpdateHandler(mock_plugin)
self.assertEqual(handler._plugin, mock_plugin)
mock_plugin.post_update_port.return_value = {"id": port_id,
"body": body.strip('"')}
mock_request.body = body
mock_request.path_url = '/v2.0/ports/{}'.format(port_id)
expected = ('{{"port": {{"id": "{0}", "body": "{1}"}}}}'
''.format(port_id, body.strip('"')))
result = handler.handle(mock_request, mock_response)
self.assertEqual(json.loads(expected), json.loads(result))