def test_get_method_unknown_controller_action(self): class Controller(object): def index(self, req, pants=None): return pants controller = Controller() resource = wsgi.Resource(controller) self.assertRaises(AttributeError, resource.get_method, None, 'create')
def test_deserialize_badtype(self): class Controller(object): def index(self, req, pants=None): return pants controller = Controller() resource = wsgi.Resource(controller) self.assertRaises(exception.InvalidContentType, resource.deserialize, controller.index, 'application/none', 'foo')
def test_dispatch(self): class Controller(object): def index(self, req, pants=None): return pants controller = Controller() resource = wsgi.Resource(controller) method = resource.get_method(None, 'index') actual = resource.dispatch(method, None, {'pants': 'off'}) expected = 'off' self.assertEqual(actual, expected)
def test_get_body_no_content_type(self): class Controller(object): def index(self, req, pants=None): return pants controller = Controller() resource = wsgi.Resource(controller) request = wsgi.Request.blank('/', method='POST') request.body = 'foo' content_type, body = resource.get_body(request) self.assertEqual(content_type, None) self.assertEqual(body, '')
def _setup_ext_routes(self, mapper, ext_mgr): for resource in ext_mgr.get_resources(): LOG.debug(_('Extended resource: %s'), resource.collection) kargs = dict(controller=wsgi.Resource(resource.controller, resource.deserializer, resource.serializer), collection=resource.collection_actions, member=resource.member_actions) if resource.parent: kargs['parent_resource'] = resource.parent mapper.resource(resource.collection, resource.collection, **kargs)
def test_get_body(self): class Controller(object): def index(self, req, pants=None): return pants controller = Controller() resource = wsgi.Resource(controller) request = wsgi.Request.blank('/', method='POST') request.headers['Content-Type'] = 'application/json' request.body = 'foo' content_type, body = resource.get_body(request) self.assertEqual(content_type, 'application/json') self.assertEqual(body, 'foo')
def test_deserialize_decorator(self): class JSONDeserializer(object): def deserialize(self, body): return 'json' class XMLDeserializer(object): def deserialize(self, body): return 'xml' class Controller(object): @wsgi.deserializers(xml=XMLDeserializer) def index(self, req, pants=None): return pants controller = Controller() resource = wsgi.Resource(controller, json=JSONDeserializer) obj = resource.deserialize(controller.index, 'application/xml', 'foo') self.assertEqual(obj, 'xml')
def test_get_action_args(self): class Controller(object): def index(self, req, pants=None): return pants controller = Controller() resource = wsgi.Resource(controller) env = { 'wsgiorg.routing_args': [ None, { 'controller': None, 'format': None, 'action': 'update', 'id': 12, } ], } expected = {'action': 'update', 'id': 12} self.assertEqual(resource.get_action_args(env), expected)
def create_resource(): return wsgi.Resource(Controller())
def create_resource(): return wsgi.Resource(VersionV2())