def test_dispatch(self): resource = wsgi.Resource(self.Controller()) req = wsgi.Request.blank('/') actual = resource.dispatch(req, 'index', action_args={'index': 'off'}) expected = 'off' self.assertEqual(expected, actual)
def _setup_routes(self, mapper): default_resource = wsgi.Resource(wsgi.DefaultMethodController(), wsgi.RequestDeserializer()) controller = vnf_pkgm_controller.create_resource() # Allowed methods on /vnf_packages resource methods = {"GET": "index", "POST": "create"} self._setup_route(mapper, "/vnf_packages", methods, controller, default_resource) # Allowed methods on /vnf_packages/{id} resource methods = {"DELETE": "delete", "GET": "show", "PATCH": "patch"} self._setup_route(mapper, "/vnf_packages/{id}", methods, controller, default_resource) # Allowed methods on /vnf_packages/{id}/package_content resource methods = { "PUT": "upload_vnf_package_content", "GET": "fetch_vnf_package_content" } self._setup_route(mapper, "/vnf_packages/{id}/package_content", methods, controller, default_resource) # Allowed methods on # /vnf_packages/{id}/package_content/upload_from_uri resource methods = {"POST": "upload_vnf_package_from_uri"} self._setup_route( mapper, "/vnf_packages/{id}/package_content/upload_from_uri", methods, controller, default_resource) # Allowed methods on /vnf_packages/{id}/vnfd methods = {"GET": "get_vnf_package_vnfd"} self._setup_route(mapper, "/vnf_packages/{id}/vnfd", methods, controller, default_resource)
def test_type_error(self): resource = wsgi.Resource(self.Controller()) request = wsgi.Request.blank("/", method='GET', headers={'Content-Type': "json"}) response = resource(request) self.assertEqual(400, response.status_int)
def test_wrong_content_type_bad_request_error(self): resource = wsgi.Resource(self.Controller()) request = wsgi.Request.blank("/", method='POST', headers={'Content-Type': "unknow"}) response = resource(request) self.assertEqual(400, response.status_int)
def create_resource(): body_deserializers = { 'application/zip': wsgi.ZipDeserializer() } deserializer = wsgi.RequestDeserializer( body_deserializers=body_deserializers) return wsgi.Resource(VnfPkgmController(), deserializer=deserializer)
def test_wrong_content_type_server_error(self): resource = wsgi.Resource(None, self.my_fault_body_function) request = wsgi.Request.blank("/", method='POST', headers={'Content-Type': "unknow"}) response = resource(request) self.assertEqual(500, response.status_int)
def test_dispatch(self): resource = wsgi.Resource(self.Controller(), self.my_fault_body_function) actual = resource.dispatch(resource.controller, 'index', action_args={'index': 'off'}) expected = 'off' self.assertEqual(expected, actual)
def test_wrong_content_type_throws_unsupported_media_type_error(self): resource = wsgi.Resource(None) request = wsgi.Request.blank("/", body=b"{some:json}", method='POST', headers={'Content-Type': "xxx"}) response = resource(request) self.assertEqual(400, response.status_int)
def test_wrong_content_type_throws_unsupported_media_type_error(self): def my_fault_body_function(): return 'off' resource = wsgi.Resource(None, my_fault_body_function) request = wsgi.Request.blank( "/", body="{some:json}", method='POST', headers={'Content-Type': "xxx"}) response = resource(request) self.assertEqual(response.status_int, 400)
def test_malformed_request_body_throws_bad_request(self): resource = wsgi.Resource(None) request = wsgi.Request.blank( "/", body=b"{mal:formed", method='POST', headers={'Content-Type': "application/json"}) response = resource(request) self.assertEqual(400, response.status_int)
def test_malformed_request_body_throws_bad_request(self): def my_fault_body_function(): return 'off' resource = wsgi.Resource(None, my_fault_body_function) request = wsgi.Request.blank( "/", body="{mal:formed", method='POST', headers={'Content-Type': "application/json"}) response = resource(request) self.assertEqual(response.status_int, 400)
def test_type_error(self): resource = wsgi.Resource(self.Controller(), self.my_fault_body_function) request = wsgi.Request.blank("/", method='POST', headers={'Content-Type': "json"}) response = resource.dispatch(request, action='index', action_args='test') self.assertEqual(400, response.status_int)
def test_dispatch_unknown_controller_action(self): class Controller(object): def index(self, request, pants=None): return pants def my_fault_body_function(): return 'off' resource = wsgi.Resource(Controller(), my_fault_body_function) self.assertRaises(AttributeError, resource.dispatch, resource.controller, 'create', {})
def test_type_error(self): class Controller(object): def index(self, request, index=None): return index def my_fault_body_function(): return 'off' resource = wsgi.Resource(Controller(), my_fault_body_function) request = wsgi.Request.blank( "/", method='POST', headers={'Content-Type': "xml"}) response = resource.dispatch( request, action='index', action_args='test') self.assertEqual(400, response.status_int)
def test_dispatch(self): class Controller(object): def index(self, request, index=None): return index def my_fault_body_function(): return 'off' resource = wsgi.Resource(Controller(), my_fault_body_function) actual = resource.dispatch( resource.controller, 'index', action_args={'index': 'off'}) expected = 'off' self.assertEqual(actual, expected)
def test_call_resource_class_bad_request(self): class FakeRequest(object): def __init__(self): self.url = 'http://where.no' self.environ = 'environ' self.body = 'body' def method(self): pass def best_match_content_type(self): return 'best_match_content_type' resource = wsgi.Resource(self.Controller()) request = FakeRequest() result = resource(request) self.assertEqual(415, result.status_int)
def test_call_resource_class_bad_request_error(self): class FakeRequest(object): def __init__(self): self.url = 'http://where.no' self.environ = 'environ' self.body = '{"Content-Type": "json"}' def method(self): pass def best_match_content_type(self): return 'application/json' resource = wsgi.Resource(self.Controller()) request = FakeRequest() result = resource(request) self.assertEqual(400, result.status_int)
def _setup_routes(self, mapper): default_resource = wsgi.Resource(wsgi.DefaultMethodController(), wsgi.RequestDeserializer()) controller = vnf_lcm_controller.create_resource() # Allowed methods on /vnflcm/v1/vnf_instances resource methods = {"GET": "index", "POST": "create"} self._setup_route(mapper, "/vnf_instances", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId} resource methods = {"DELETE": "delete", "GET": "show"} self._setup_route(mapper, "/vnf_instances/{id}", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId}/instantiate resource methods = {"POST": "instantiate"} self._setup_route(mapper, "/vnf_instances/{id}/instantiate", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId}/heal resource methods = {"POST": "heal"} self._setup_route(mapper, "/vnf_instances/{id}/heal", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId}/terminate resource methods = {"POST": "terminate"} self._setup_route(mapper, "/vnf_instances/{id}/terminate", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId}/heal resource methods = {"POST": "heal"} self._setup_route(mapper, "/vnf_instances/{id}/heal", methods, controller, default_resource)
def test_call_resource_class_bad_request(self): class Controller(object): def index(self, request, index=None): return index def my_fault_body_function(): return b'off' class FakeRequest(object): def __init__(self): self.url = 'http://where.no' self.environ = 'environ' self.body = b'body' def method(self): pass def best_match_content_type(self): return 'best_match_content_type' resource = wsgi.Resource(Controller(), my_fault_body_function) request = FakeRequest() result = resource(request) self.assertEqual(400, result.status_int)
def test_call_resource_class_internal_error(self): class Controller(object): def index(self, request, index=None): return index def my_fault_body_function(): return 'off' class FakeRequest(object): def __init__(self): self.url = 'http://where.no' self.environ = 'environ' self.body = '{"Content-Type": "xml"}' def method(self): pass def best_match_content_type(self): return 'application/json' resource = wsgi.Resource(Controller(), my_fault_body_function) request = FakeRequest() result = resource(request) self.assertEqual(500, result.status_int)
def test_dispatch_unknown_controller_action(self): resource = wsgi.Resource(self.Controller(), self.my_fault_body_function) self.assertRaises(AttributeError, resource.dispatch, resource.controller, 'create', {})
def _setup_routes(self, mapper): default_resource = wsgi.Resource(wsgi.DefaultMethodController(), wsgi.RequestDeserializer()) controller = vnf_lcm_controller.create_resource() # Allowed methods on /vnflcm/v1/vnf_instances resource methods = {"GET": "index", "POST": "create"} self._setup_route(mapper, "/vnf_instances", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId} resource methods = {"DELETE": "delete", "GET": "show", "PATCH": "update"} self._setup_route(mapper, "/vnf_instances/{id}", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId}/instantiate resource methods = {"POST": "instantiate"} self._setup_route(mapper, "/vnf_instances/{id}/instantiate", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId}/heal resource methods = {"POST": "heal"} self._setup_route(mapper, "/vnf_instances/{id}/heal", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_lcm_op_occs/{vnfLcmOpOccId} resource methods = {"GET": "show_lcm_op_occs"} self._setup_route(mapper, "/vnf_lcm_op_occs/{id}", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId}/terminate resource methods = {"POST": "terminate"} self._setup_route(mapper, "/vnf_instances/{id}/terminate", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId}/heal resource methods = {"POST": "heal"} self._setup_route(mapper, "/vnf_instances/{id}/heal", methods, controller, default_resource) # Allowed methods on # /vnflcm/v1/vnf_instances/{vnfInstanceId}/scale resource methods = {"POST": "scale"} self._setup_route(mapper, "/vnf_instances/{id}/scale", methods, controller, default_resource) # Allowed methods on # {apiRoot}/vnflcm/v1/vnf_lcm_op_occs/{vnfLcmOpOccId}/rollback resource methods = {"POST": "rollback"} self._setup_route(mapper, "/vnf_lcm_op_occs/{id}/rollback", methods, controller, default_resource) methods = {"GET": "subscription_list", "POST": "register_subscription"} self._setup_route(mapper, "/subscriptions", methods, controller, default_resource) methods = {"GET": "subscription_show", "DELETE": "delete_subscription"} self._setup_route(mapper, "/subscriptions/{subscriptionId}", methods, controller, default_resource)
def create_resource(): return wsgi.Resource(VnfLcmController())