Пример #1
0
    def test_make_middleware_disabled(self):
        def app(environ, start_response):
            start_response('200 OK', [('content-type', 'text/html')])
            return ['Hello world!']

        app = make_errormator_middleware(app, {'errormator':'false'})
        self.assertFalse(isinstance(app, ErrormatorWSGIWrapper))
Пример #2
0
    def test_make_middleware_disabled(self):
        def app(environ, start_response):
            start_response('200 OK', [('content-type', 'text/html')])
            return ['Hello world!']

        app = make_errormator_middleware(app, {'errormator': 'false'})
        self.assertFalse(isinstance(app, ErrormatorWSGIWrapper))
Пример #3
0
    def test_make_middleware(self):
        def app(environ, start_response):
            start_response('200 OK', [('content-type', 'text/html')])
            return ['Hello world!']

        app = make_errormator_middleware(app, {'errormator.api_key': '12345'})
        self.assertTrue(isinstance(app, ErrormatorWSGIWrapper))
Пример #4
0
    def test_make_middleware(self):
        def app(environ, start_response):
            start_response('200 OK', [('content-type', 'text/html')])
            return ['Hello world!']

        app = make_errormator_middleware(app, {'errormator.api_key': '12345'})
        self.assertTrue(isinstance(app, ErrormatorWSGIWrapper))
Пример #5
0
    def test_normal_request(self):
        def app(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/html')])
            return ['Hello World!']

        req = Request.blank('http://localhost/test')
        app = make_errormator_middleware(app, global_config=timing_conf)
        req.get_response(app)
        self.assertEqual(len(app.errormator_client.slow_report_queue), 0)
Пример #6
0
    def test_normal_request(self):
        def app(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/html')])
            return ['Hello World!']

        req = Request.blank('http://localhost/test')
        app = make_errormator_middleware(app, global_config=timing_conf)
        req.get_response(app)
        self.assertEqual(len(app.errormator_client.slow_report_queue), 0)
Пример #7
0
    def test_logging_request(self):
        def app(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/html')])
            logging.warning('test logging')
            logging.critical('test logging critical')
            return ['Hello World!']

        req = Request.blank('http://localhost/test')
        app = make_errormator_middleware(app, global_config=timing_conf)
        req.get_response(app)
        self.assertGreaterEqual(len(app.errormator_client.log_queue), 2)
Пример #8
0
    def test_error_request(self):
        def app(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/html')])
            raise Exception('WTF?')
            return ['Hello World!']

        req = Request.blank('http://localhost/test')
        app = make_errormator_middleware(app, global_config=timing_conf)
        app.errormator_client.config['reraise_exceptions'] = False
        req.get_response(app)
        self.assertEqual(len(app.errormator_client.report_queue), 1)
Пример #9
0
    def test_logging_request(self):
        def app(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/html')])
            logging.warning('test logging')
            logging.critical('test logging critical')
            return ['Hello World!']

        req = Request.blank('http://localhost/test')
        app = make_errormator_middleware(app, global_config=timing_conf)
        app.errormator_client.last_submit = datetime.datetime.now()
        req.get_response(app)
        self.assertGreaterEqual(len(app.errormator_client.log_queue), 2)
Пример #10
0
    def test_error_request(self):
        def app(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/html')])
            raise Exception('WTF?')
            return ['Hello World!']

        req = Request.blank('http://localhost/test')
        app = make_errormator_middleware(app, global_config=timing_conf)
        app.errormator_client.config['reraise_exceptions'] = False
        app.errormator_client.last_submit = datetime.datetime.now()
        req.get_response(app)
        self.assertEqual(len(app.errormator_client.report_queue), 1)
Пример #11
0
    def test_timing_request(self):
        def app(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/html')])
            time.sleep(0.1)
            try:
                import sqlite3
            except ImportError:
                return
            conn = sqlite3.connect(':memory:')
            c = conn.cursor()
            c.execute('''SELECT 1+2+3 AS result''')
            c.fetchone()
            c.close()
            conn.close()
            return ['Hello World!']

        req = Request.blank('http://localhost/test')
        app = make_errormator_middleware(app, global_config=timing_conf)
        req.get_response(app)
        stats, result = get_local_storage(local_timing).get_thread_stats()
        self.assertGreater(stats['main'], 0)
        self.assertGreater(stats['sql'], 0)
Пример #12
0
    def test_timing_request(self):
        def app(environ, start_response):
            start_response('200 OK', [('Content-Type', 'text/html')])
            time.sleep(0.1)
            try:
                import sqlite3
            except ImportError:
                return
            conn = sqlite3.connect(':memory:')
            c = conn.cursor()
            c.execute('''SELECT 1+2+3 AS result''')
            c.fetchone()
            c.close()
            conn.close()
            return ['Hello World!']

        req = Request.blank('http://localhost/test')
        app = make_errormator_middleware(app, global_config=timing_conf)
        req.get_response(app)
        stats, result = get_local_storage(local_timing).get_thread_stats()
        self.assertGreater(stats['main'], 0)
        self.assertGreater(stats['sql'], 0)