def setUp(self): super(ApiV2TestCase, self).setUp() # Ensure the v2 API is enabled self.config(enable_api_v2=True, group='service:api') # Create the application self.app = api_v2.factory({}) # Inject the NormalizeURIMiddleware middleware self.app = middleware.NormalizeURIMiddleware(self.app) # Inject the ValidationError middleware self.app = middleware.APIv2ValidationErrorMiddleware(self.app) # Inject the FaultWrapper middleware self.app = middleware.FaultWrapperMiddleware(self.app) # Inject the TestContext middleware self.app = middleware.TestContextMiddleware(self.app, self.admin_context.tenant, self.admin_context.tenant) # Obtain a test client self.client = TestApp(self.app)
def test_notify_of_fault(self): self.config(notify_api_faults=True) rpc.init(cfg.CONF) app = middleware.FaultWrapperMiddleware({}) class RaisingRequest(FakeRequest): def get_response(self, request): raise exceptions.DuplicateDomain() request = RaisingRequest() ctxt = context.DesignateContext() ctxt.request_id = 'one' request.environ['context'] = ctxt # Process the request app(request) notifications = self.get_notifications() self.assertEqual(1, len(notifications)) ctxt, message, priority = notifications.pop() self.assertEqual('ERROR', message['priority']) self.assertEqual('dns.api.fault', message['event_type']) self.assertIn('timestamp', message) self.assertIn('publisher_id', message)
def setUp(self): super(ApiV1Test, self).setUp() # Ensure the v1 API is enabled self.config(enable_api_v1=True, group='service:api') # Create the application self.app = api_v1.factory({}) # Inject the NormalizeURIMiddleware middleware self.app.wsgi_app = middleware.NormalizeURIMiddleware( self.app.wsgi_app) # Inject the FaultWrapper middleware self.app.wsgi_app = middleware.FaultWrapperMiddleware( self.app.wsgi_app) # Inject the ValidationError middleware self.app.wsgi_app = middleware.APIv1ValidationErrorMiddleware( self.app.wsgi_app) # Inject the TestAuth middleware self.app.wsgi_app = middleware.TestContextMiddleware( self.app.wsgi_app, self.admin_context.tenant, self.admin_context.user) # Obtain a test client self.client = self.app.test_client()
def setUp(self): super(APIV2ZoneImportExportTest, self).setUp() self.config(enable_api_admin=True, group='service:api') self.config(enabled_extensions_admin=['zones'], group='service:api') # Create the application adminapp = admin_api.factory({}) # Inject the NormalizeURIMiddleware middleware adminapp = middleware.NormalizeURIMiddleware(adminapp) # Inject the FaultWrapper middleware adminapp = middleware.FaultWrapperMiddleware(adminapp) # Inject the TestContext middleware adminapp = middleware.TestContextMiddleware(adminapp, self.admin_context.tenant, self.admin_context.tenant) # Obtain a test client self.adminclient = TestApp(adminapp)
def setUp(self): super(ApiV2TestCase, self).setUp() # Ensure the v2 API is enabled self.config(enable_api_v2=True, group='service:api') # Create the application self.app = api_v2.factory({}) # Inject the FaultWrapper middleware self.app = middleware.FaultWrapperMiddleware(self.app) # Inject the NoAuth middleware self.app = middleware.NoAuthContextMiddleware(self.app) # Obtain a test client self.client = TestApp(self.app) # Create and start an instance of the central service self.central_service = self.get_central_service() self.central_service.start()
def test_notify_of_fault(self, mock_notifier): self.config(notify_api_faults=True) rpc.init(cfg.CONF) app = middleware.FaultWrapperMiddleware({}) class RaisingRequest(FakeRequest): def get_response(self, request): raise exceptions.DuplicateZone() request = RaisingRequest() ctxt = context.DesignateContext() ctxt.request_id = 'one' request.environ['context'] = ctxt # Process the request app(request) self.assertEqual(1, mock_notifier.call_count) mock_notifier.call_args( ctxt, 'dns.api.fault', {"url": None, "status": 409, "exception": ""})
def setUp(self): super(ApiV1Test, self).setUp() # Ensure the v1 API is enabled self.config(enable_api_v1=True, group='service:api') # Create the application self.app = api_v1.factory({}) # Inject the FaultWrapper middleware self.app.wsgi_app = middleware.FaultWrapperMiddleware( self.app.wsgi_app) # Inject the TestAuth middleware self.app.wsgi_app = middleware.TestContextMiddleware( self.app.wsgi_app, self.admin_context.tenant_id, self.admin_context.user_id) # Obtain a test client self.client = self.app.test_client() self.central_service = self.start_service('central')
def setUp(self): super(AdminApiTestCase, self).setUp() # Ensure the v2 API is enabled self.config(enable_api_admin=True, group='service:api') # Create the application self.app = admin_api.factory({}) # Inject the NormalizeURIMiddleware middleware self.app = middleware.NormalizeURIMiddleware(self.app) # Inject the FaultWrapper middleware self.app = middleware.FaultWrapperMiddleware(self.app) # Inject the TestContext middleware self.app = middleware.TestContextMiddleware( self.app, self.admin_context.project_id, self.admin_context.project_id) # Obtain a test client self.client = TestApp(self.app)