def test_invalid_extensions_are_not_registered(self):
class InvalidExtension(object):
- """
+ """Invalid extension.
+
This Extension doesn't implement extension methods :
get_name, get_description, get_namespace and get_updated
"""
def test_extensions_are_not_loaded_for_plugins_unaware_of_extensions(self):
class ExtensionUnawarePlugin(object):
- """
- This plugin does not implement supports_extension method.
+ """This plugin does not implement supports_extension method.
+
Extensions will not be loaded when this plugin is used.
"""
pass
def test_extensions_not_loaded_for_plugin_without_expected_interface(self):
class PluginWithoutExpectedIface(object):
- """
- Plugin does not implement get_foo method as expected by extension
- """
+ """Does not implement get_foo method as expected by extension."""
supported_extension_aliases = ["supported_extension"]
plugin_info = {constants.CORE: PluginWithoutExpectedIface()}
def test_extensions_are_loaded_for_plugin_with_expected_interface(self):
class PluginWithExpectedInterface(object):
- """
- This Plugin implements get_foo method as expected by extension
- """
+ """Implements get_foo method as expected by extension."""
supported_extension_aliases = ["supported_extension"]
def get_foo(self, bar=None):
def test_extensions_expecting_quantum_plugin_interface_are_loaded(self):
class ExtensionForQuamtumPluginInterface(ext_stubs.StubExtension):
- """
- This Extension does not implement get_plugin_interface method.
+ """This Extension does not implement get_plugin_interface method.
+
This will work with any plugin implementing QuantumPluginBase
"""
pass
def test_extensions_without_need_for__plugin_interface_are_loaded(self):
class ExtensionWithNoNeedForPluginInterface(ext_stubs.StubExtension):
- """
- This Extension does not need any plugin interface.
+ """This Extension does not need any plugin interface.
+
This will work with any plugin implementing QuantumPluginBase
"""
def get_plugin_interface(self):
class SerializerTest(base.BaseTestCase):
def test_serialize_unknown_content_type(self):
- """
- Test serialize verifies that exception InvalidContentType is raised
- """
+ """Verify that exception InvalidContentType is raised."""
input_dict = {'servers': {'test': 'pass'}}
content_type = 'application/unknown'
serializer = wsgi.Serializer()
input_dict, content_type)
def test_get_deserialize_handler_unknown_content_type(self):
- """
- Test get deserialize verifies
- that exception InvalidContentType is raised
- """
+ """Verify that exception InvalidContentType is raised."""
content_type = 'application/unknown'
serializer = wsgi.Serializer()
serializer.get_deserialize_handler, content_type)
def test_serialize_content_type_json(self):
- """
- Test serialize with content type json
- """
+ """Test serialize with content type json."""
input_data = {'servers': ['test=pass']}
content_type = 'application/json'
serializer = wsgi.Serializer(default_xmlns="fake")
self.assertEqual('{"servers": ["test=pass"]}', result)
def test_serialize_content_type_xml(self):
- """
- Test serialize with content type xml
- """
+ """Test serialize with content type xml."""
input_data = {'servers': ['test=pass']}
content_type = 'application/xml'
serializer = wsgi.Serializer(default_xmlns="fake")
self.assertEqual(expected, result)
def test_deserialize_raise_bad_request(self):
- """
- Test serialize verifies that exception is raises
- """
+ """Test serialize verifies that exception is raises."""
content_type = 'application/unknown'
data_string = 'test'
serializer = wsgi.Serializer(default_xmlns="fake")
serializer.deserialize, data_string, content_type)
def test_deserialize_json_content_type(self):
- """
- Test Serializer.deserialize with content type json
- """
+ """Test Serializer.deserialize with content type json."""
content_type = 'application/json'
data_string = '{"servers": ["test=pass"]}'
serializer = wsgi.Serializer(default_xmlns="fake")
self.assertEqual({'body': {u'servers': [u'test=pass']}}, result)
def test_deserialize_xml_content_type(self):
- """
- Test deserialize with content type xml
- """
+ """Test deserialize with content type xml."""
content_type = 'application/xml'
data_string = (
'<servers xmlns="fake">'
self.assertEqual(expected, result)
def test_deserialize_xml_content_type_with_meta(self):
- """
- Test deserialize with content type xml with meta
- """
+ """Test deserialize with content type xml with meta."""
content_type = 'application/xml'
data_string = (
'<servers>'
self.assertEqual(expected, result)
def test_serialize_xml_root_key_is_dict(self):
- """
- Test Serializer.serialize with content type xml with meta dict
- """
+ """Test Serializer.serialize with content type xml with meta dict."""
content_type = 'application/xml'
data = {'servers': {'network': (2, 3)}}
metadata = {'xmlns': 'fake'}
self.assertEqual(result, expected)
def test_serialize_xml_root_key_is_list(self):
- """
- Test serialize with content type xml with meta list
- """
+ """Test serialize with content type xml with meta list."""
input_dict = {'servers': ['test=pass']}
content_type = 'application/xml'
metadata = {'application/xml': {
self.deserializer = wsgi.RequestDeserializer(self.body_deserializers)
def test_get_deserializer(self):
- """
- Test RequestDeserializer.get_body_deserializer
- """
+ """Test RequestDeserializer.get_body_deserializer."""
expected_json_serializer = self.deserializer.get_body_deserializer(
'application/json')
expected_xml_serializer = self.deserializer.get_body_deserializer(
self.body_deserializers['application/xml'])
def test_get_expected_content_type(self):
- """
- Test RequestDeserializer.get_expected_content_type
- """
+ """Test RequestDeserializer.get_expected_content_type."""
request = wsgi.Request.blank('/')
request.headers['Accept'] = 'application/json'
'application/json')
def test_get_action_args(self):
- """
- Test RequestDeserializer.get_action_args
- """
+ """Test RequestDeserializer.get_action_args."""
env = {
'wsgiorg.routing_args': [None, {
'controller': None,
self.deserializer.get_action_args(env), expected)
def test_deserialize(self):
- """
- Test RequestDeserializer.deserialize
- """
+ """Test RequestDeserializer.deserialize."""
with mock.patch.object(
self.deserializer, 'get_action_args') as mock_method:
mock_method.return_value = {'action': 'create'}
self.assertEqual(expected, deserialized)
def test_get_body_deserializer_unknown_content_type(self):
- """
- Test get body deserializer verifies
- that exception InvalidContentType is raised
- """
+ """Verify that exception InvalidContentType is raised."""
content_type = 'application/unknown'
deserializer = wsgi.RequestDeserializer()
self.assertRaises(
self.body_serializers, HeadersSerializer())
def test_serialize_unknown_content_type(self):
- """
- Test serialize verifies
- that exception InvalidContentType is raised
- """
+ """Verify that exception InvalidContentType is raised."""
self.assertRaises(
exception.InvalidContentType,
self.serializer.serialize,
{}, 'application/unknown')
def test_get_body_serializer(self):
- """
- Test get body serializer verifies
- that exception InvalidContentType is raised
- """
+ """Verify that exception InvalidContentType is raised."""
self.assertRaises(
exception.InvalidContentType,
self.serializer.get_body_serializer, 'application/unknown')
def test_get_serializer(self):
- """
- Test ResponseSerializer.get_body_serializer
- """
+ """Test ResponseSerializer.get_body_serializer."""
content_type = 'application/json'
self.assertEqual(
self.serializer.get_body_serializer(content_type),
class ActionDispatcherTest(base.BaseTestCase):
def test_dispatch(self):
- """
- Test ActionDispatcher.dispatch
- """
+ """Test ActionDispatcher.dispatch."""
serializer = wsgi.ActionDispatcher()
serializer.create = lambda x: x
'pants')
def test_dispatch_action_None(self):
- """
- Test ActionDispatcher.dispatch with none action
- """
+ """Test ActionDispatcher.dispatch with none action."""
serializer = wsgi.ActionDispatcher()
serializer.create = lambda x: x + ' pants'
serializer.default = lambda x: x + ' trousers'
deserializer.deserialize(data), as_dict)
def test_default_raise_Malformed_Exception(self):
- """
- Test verifies JsonDeserializer.default
- raises exception MalformedRequestBody correctly
+ """Test JsonDeserializer.default.
+
+ Test verifies JsonDeserializer.default raises exception
+ MalformedRequestBody correctly.
"""
data_string = ""
deserializer = wsgi.JSONDeserializer()
{'body': {u'a': {u'b': u'test'}}}, deserializer(xml))
def test_default_raise_Malformed_Exception(self):
- """
- Test verifies that exception MalformedRequestBody is raised
- """
+ """Verify that exception MalformedRequestBody is raised."""
data_string = ""
deserializer = wsgi.XMLDeserializer()