def test_mw_exc_success(self): """Ensure exceptions can be properly handled by other middleware. No error should be reported in the span. """ from .app.middleware import ExceptionMiddleware, ExceptionToSuccessMiddleware wsgiapp = ExceptionMiddleware(self._wsgiapp) wsgiapp = ExceptionToSuccessMiddleware(wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service='web') app = fixture.TestApp(app) app.get(url_for(controller='root', action='index')) spans = self.tracer.writer.pop() assert spans, spans assert len(spans) == 1 span = spans[0] assert span.service == 'web' assert span.resource == 'None.None' assert span.error == 0 assert span.get_tag('http.status_code') == '200' assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None
def test_middleware_exception(self): """Ensure exceptions raised in middleware are properly handled. Uncaught exceptions should result in error tagged spans. """ from .app.middleware import ExceptionMiddleware wsgiapp = ExceptionMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service='web') app = fixture.TestApp(app) with pytest.raises(Exception): app.get(url_for(controller='root', action='index')) spans = self.tracer.writer.pop() assert spans, spans assert len(spans) == 1 span = spans[0] assert span.service == 'web' assert span.resource == 'None.None' assert span.error == 1 assert span.get_tag('http.status_code') == '500' assert span.get_tag(errors.ERROR_MSG) == 'Middleware exception' assert span.get_tag(errors.ERROR_TYPE) == 'exceptions.Exception' assert span.get_tag(errors.ERROR_STACK)
def setUp(self): super(PylonsTestCase, self).setUp() # initialize a real traced Pylons app wsgiapp = loadapp('config:test.ini', relative_to=PylonsTestCase.conf_dir) self._wsgiapp = wsgiapp app = PylonsTraceMiddleware(wsgiapp, self.tracer, service='web') self.app = fixture.TestApp(app)
def test_controller_exception(self): """Ensure exceptions thrown in controllers can be handled. No error tags should be set in the span. """ from .app.middleware import ExceptionToSuccessMiddleware wsgiapp = ExceptionToSuccessMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service='web') app = fixture.TestApp(app) app.get(url_for(controller='root', action='raise_exception')) spans = self.tracer.writer.pop() assert spans, spans assert len(spans) == 1 span = spans[0] assert span.service == 'web' assert span.resource == 'root.raise_exception' assert span.error == 0 assert span.get_tag('http.status_code') == '200' assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None assert span.span_type == 'http'
def test_middleware_exception(self): """Ensure exceptions raised in middleware are properly handled. Uncaught exceptions should result in error tagged spans. """ from .app.middleware import ExceptionMiddleware wsgiapp = ExceptionMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service="web") app = fixture.TestApp(app) with pytest.raises(Exception): app.get(url_for(controller="root", action="index")) spans = self.pop_spans() assert spans, spans assert len(spans) == 1 span = spans[0] assert_is_measured(span) assert span.service == "web" assert span.resource == "None.None" assert span.error == 1 assert span.get_tag(http.URL) == "http://localhost:80/" assert_span_http_status_code(span, 500) assert span.get_tag(errors.ERROR_MSG) == "Middleware exception" assert span.get_tag(errors.ERROR_TYPE) == "exceptions.Exception" assert span.get_tag(errors.ERROR_STACK)
def test_controller_exception(self): """Ensure exceptions thrown in controllers can be handled. No error tags should be set in the span. """ from .app.middleware import ExceptionToSuccessMiddleware wsgiapp = ExceptionToSuccessMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service="web") app = fixture.TestApp(app) app.get(url_for(controller="root", action="raise_exception")) spans = self.pop_spans() assert spans, spans assert len(spans) == 1 span = spans[0] assert_is_measured(span) assert span.service == "web" assert span.resource == "root.raise_exception" assert span.error == 0 assert span.get_tag(http.URL) == "http://localhost:80/raise_exception" assert_span_http_status_code(span, 200) assert http.QUERY_STRING not in span.meta assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None assert span.span_type == "web"
def test_mw_exc_success(self): """Ensure exceptions can be properly handled by other middleware. No error should be reported in the span. """ from .app.middleware import ExceptionMiddleware from .app.middleware import ExceptionToSuccessMiddleware wsgiapp = ExceptionMiddleware(self._wsgiapp) wsgiapp = ExceptionToSuccessMiddleware(wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service="web") app = fixture.TestApp(app) app.get(url_for(controller="root", action="index")) spans = self.pop_spans() assert spans, spans assert len(spans) == 1 span = spans[0] assert_is_measured(span) assert span.service == "web" assert span.resource == "None.None" assert span.error == 0 assert span.get_tag(http.URL) == "http://localhost:80/" assert_span_http_status_code(span, 200) assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None
def setUp(self): # initialize a real traced Pylons app self.tracer = get_dummy_tracer() wsgiapp = loadapp('config:test.ini', relative_to=PylonsTestCase.conf_dir) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service='web') self.app = fixture.TestApp(app)
def __init__(self, *args, **kwargs): import sys self.wsgiapp = pylons.test.pylonsapp self.config = self.wsgiapp.config self.app = fixture.TestApp(self.wsgiapp) url._push_object(URLGenerator(self.config['routes.map'], environ)) TestRollback.__init__(self, *args, **kwargs)
def create_fixture_app(app): local.worker = local.Process() local.request = local.Process() app = wsgi.create_WSGIApp(app) app.set_sessions_manager(SessionsWithPickledStates()) app.start() return fixture.TestApp(app)
def test_exc_client_failure(self): from .app.middleware import ExceptionToClientErrorMiddleware wsgiapp = ExceptionToClientErrorMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service='web') app = fixture.TestApp(app) app.get(url_for(controller='root', action='raise_exception'), status=404) spans = self.tracer.writer.pop() assert spans, spans assert len(spans) == 1 span = spans[0] assert span.service == 'web' assert span.resource == 'root.raise_exception' assert span.error == 0 assert span.get_tag('http.status_code') == '404' assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None
def test_exc_success(self): from .app.middleware import ExceptionToSuccessMiddleware wsgiapp = ExceptionToSuccessMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service='web') app = fixture.TestApp(app) app.get(url_for(controller='root', action='raise_exception')) spans = self.tracer.writer.pop() ok_(spans, spans) eq_(len(spans), 1) span = spans[0] eq_(span.service, 'web') eq_(span.resource, 'root.raise_exception') eq_(span.error, 0) eq_(span.get_tag('http.status_code'), '200') eq_(span.get_tag(errors.ERROR_MSG), None) eq_(span.get_tag(errors.ERROR_TYPE), None) eq_(span.get_tag(errors.ERROR_STACK), None)
def test_exc_success(self): from .app.middleware import ExceptionToSuccessMiddleware wsgiapp = ExceptionToSuccessMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service='web') app = fixture.TestApp(app) app.get(url_for(controller='root', action='raise_exception')) spans = self.tracer.writer.pop() assert spans, spans assert len(spans) == 1 span = spans[0] assert span.service == 'web' assert span.resource == 'root.raise_exception' assert span.error == 0 assert span.get_tag(http.URL) == 'http://localhost:80/raise_exception' assert span.get_metric('http.status_code') == 200 assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None
def test_exc_success(self): from .app.middleware import ExceptionToSuccessMiddleware wsgiapp = ExceptionToSuccessMiddleware(self._wsgiapp) app = PylonsTraceMiddleware(wsgiapp, self.tracer, service="web") app = fixture.TestApp(app) app.get(url_for(controller="root", action="raise_exception")) spans = self.pop_spans() assert spans, spans assert len(spans) == 1 span = spans[0] assert_is_measured(span) assert span.service == "web" assert span.resource == "root.raise_exception" assert span.error == 0 assert span.get_tag(http.URL) == "http://localhost:80/raise_exception" assert_span_http_status_code(span, 200) assert span.get_tag(errors.ERROR_MSG) is None assert span.get_tag(errors.ERROR_TYPE) is None assert span.get_tag(errors.ERROR_STACK) is None
sys.path.append(os.path.abspath('.')) import mediacore # -- Environment Setup ----------------------------------------------------- # We need a proper request environment to be able to properly import # controllers and forms for the sake of autodoc. from os import path from paste import fixture, deploy, registry # Load the WSGI app config = 'development.ini' config_path = path.join(path.dirname(__file__), '..', config) app = deploy.loadapp('config:%s' % config_path) test_app = fixture.TestApp(app) # Query the test app to setup the environment response = test_app.get('/_test_vars') request_id = int(response.body) # Disable restoration during test_app requests test_app.pre_request_hook = lambda self: registry.restorer.restoration_end() test_app.post_request_hook = lambda self: registry.restorer.restoration_begin(request_id) # Restore the state of the Pylons special objects (StackedObjectProxies) registry.restorer.restoration_begin(request_id) # -- General configuration -----------------------------------------------------
def setUp(self): self.testApp = fixture.TestApp(webapp.app.wsgifunc())