From f9794b521f4760a7a95264db8c5569ee5a9465fc Mon Sep 17 00:00:00 2001 From: Josh Conant Date: Thu, 19 Mar 2015 15:17:40 +0000 Subject: [PATCH] Removing XML serialization code The classes no longer exists in neutron upstream. RM11046 --- quark/api/extensions/ports_quark.py | 16 +------ quark/tests/api/__init__.py | 0 quark/tests/api/extensions/__init__.py | 0 .../tests/api/extensions/test_ports_quark.py | 44 +++++++++++++++++++ 4 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 quark/tests/api/__init__.py create mode 100644 quark/tests/api/extensions/__init__.py create mode 100644 quark/tests/api/extensions/test_ports_quark.py diff --git a/quark/api/extensions/ports_quark.py b/quark/api/extensions/ports_quark.py index f1ed636..2d964a6 100644 --- a/quark/api/extensions/ports_quark.py +++ b/quark/api/extensions/ports_quark.py @@ -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'] diff --git a/quark/tests/api/__init__.py b/quark/tests/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/quark/tests/api/extensions/__init__.py b/quark/tests/api/extensions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/quark/tests/api/extensions/test_ports_quark.py b/quark/tests/api/extensions/test_ports_quark.py new file mode 100644 index 0000000..879e176 --- /dev/null +++ b/quark/tests/api/extensions/test_ports_quark.py @@ -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))