return param_str.rstrip('&')
-def raise_http_conflict_for_instance_invalid_state(exc, action):
- """Return a webob.exc.HTTPConflict instance containing a message
- appropriate to return via the API based on the original
- InstanceInvalidState exception.
- """
- attr = exc.kwargs.get('attr')
- state = exc.kwargs.get('state')
- if attr and state:
- msg = _("Cannot '%(action)s' while instance is in %(attr)s %(state)s")
- else:
- # At least give some meaningful message
- msg = _("Instance is in an invalid state for '%(action)s'")
- raise webob.exc.HTTPConflict(explanation=msg % locals())
-
-
class MetadataDeserializer(wsgi.MetadataXMLDeserializer):
def deserialize(self, text):
dom = minidom.parseString(text)
actual = common.get_version_from_href(fixture)
self.assertEqual(actual, expected)
- def test_raise_http_conflict_for_instance_invalid_state(self):
- # Correct args
- exc = exception.InstanceInvalidState(attr='fake_attr',
- state='fake_state', method='fake_method')
- try:
- common.raise_http_conflict_for_instance_invalid_state(exc,
- 'meow')
- except Exception, e:
- self.assertTrue(isinstance(e, webob.exc.HTTPConflict))
- msg = str(e)
- self.assertEqual(msg,
- "Cannot 'meow' while instance is in fake_attr fake_state")
- else:
- self.fail("webob.exc.HTTPConflict was not raised")
-
- # Incorrect args
- exc = exception.InstanceInvalidState()
- try:
- common.raise_http_conflict_for_instance_invalid_state(exc,
- 'meow')
- except Exception, e:
- self.assertTrue(isinstance(e, webob.exc.HTTPConflict))
- msg = str(e)
- self.assertEqual(msg,
- "Instance is in an invalid state for 'meow'")
- else:
- self.fail("webob.exc.HTTPConflict was not raised")
-
class MetadataXMLDeserializationTest(test.TestCase):