Merge "Limit formatting routes when adding resources"
This commit is contained in:
@@ -90,6 +90,15 @@ class APIMapper(routes.Mapper):
|
||||
return result[0], result[1]
|
||||
return routes.Mapper.routematch(self, url, environ)
|
||||
|
||||
def connect(self, *args, **kargs):
|
||||
# NOTE(vish): Default the format part of a route to only accept json
|
||||
# and xml so it doesn't eat all characters after a '.'
|
||||
# in the url.
|
||||
kargs.setdefault('requirements', {})
|
||||
if not kargs['requirements'].get('format'):
|
||||
kargs['requirements']['format'] = 'json|xml'
|
||||
return routes.Mapper.connect(self, *args, **kargs)
|
||||
|
||||
|
||||
class ProjectMapper(APIMapper):
|
||||
def resource(self, member_name, collection_name, **kwargs):
|
||||
|
||||
@@ -666,3 +666,31 @@ class ExtensionsXMLSerializerTest(test.TestCase):
|
||||
self.assertEqual(link_nodes[i].get(key), value)
|
||||
|
||||
xmlutil.validate_schema(root, 'extensions')
|
||||
|
||||
|
||||
class ExtensionControllerIdFormatTest(test.TestCase):
|
||||
|
||||
def _bounce_id(self, test_id):
|
||||
|
||||
class BounceController(object):
|
||||
def show(self, req, id):
|
||||
return id
|
||||
res_ext = base_extensions.ResourceExtension('bounce',
|
||||
BounceController())
|
||||
manager = StubExtensionManager(res_ext)
|
||||
app = compute.APIRouter(manager)
|
||||
request = webob.Request.blank("/fake/bounce/%s" % test_id)
|
||||
response = request.get_response(app)
|
||||
return response.body
|
||||
|
||||
def test_id_with_xml_format(self):
|
||||
result = self._bounce_id('foo.xml')
|
||||
self.assertEqual(result, 'foo')
|
||||
|
||||
def test_id_with_json_format(self):
|
||||
result = self._bounce_id('foo.json')
|
||||
self.assertEqual(result, 'foo')
|
||||
|
||||
def test_id_with_bad_format(self):
|
||||
result = self._bounce_id('foo.bad')
|
||||
self.assertEqual(result, 'foo.bad')
|
||||
|
||||
Reference in New Issue
Block a user