# Path: bugsnag/wsgi/middleware.py
# class BugsnagMiddleware:
#     """
#     Notifies Bugsnag on any unhandled exception that happens while processing
#     a request in your application.
# 
#     This middleware should be installed before any middlewares that catch
#     the exception and render an error messae.
#     """
# 
#     def __init__(self, application):
#         middleware = bugsnag.configure().internal_middleware
#         if bottle_present:
#             bugsnag.configure().runtime_versions['bottle'] = bottle.__version__
#         middleware.before_notify(add_wsgi_request_data_to_notification)
#         self.application = application
# 
#     def __call__(self, environ, start_response):
#         return WrappedWSGIApp(self.application, environ, start_response)
# 
# Path: tests/utils.py
# class IntegrationTest(unittest.TestCase):
# 
#     @classmethod
#     def setUpClass(cls):
#         cls.server = FakeBugsnagServer()
# 
#     def setUp(self):
#         self.server.received = []
# 
#     def tearDown(self):
#         bugsnag.legacy.default_client.uninstall_sys_hook()
#         client = bugsnag.Client()
#         client.configuration.api_key = 'some key'
#         bugsnag.legacy.default_client = client
#         bugsnag.legacy.configuration = client.configuration
# 
#     @classmethod
#     def tearDownClass(cls):
#         cls.server.shutdown()
# 
#     def assertSentReportCount(self, count):
#         self.assertEqual(len(self.server.received), count)
# 
#     def assertExceptionName(self, received_index, event_index, name):
#         json_body = self.server.received[received_index]['json_body']
#         event = json_body['events'][event_index]
#         exception = event['exceptions'][0]
#         self.assertEqual(exception['errorClass'], name)
# 
#     @property
#     def sent_report_count(self) -> int:
#         return len(self.server.received)


from webtest import TestApp
from bottle import route, template
from bugsnag.wsgi.middleware import BugsnagMiddleware
from tests.utils import IntegrationTest
import bottle
import bugsnag
        self.assertEqual(event['exceptions'][0]['errorClass'], 'Exception')
        self.assertEqual(event['exceptions'][0]['message'], 'oh no!')
        runtime_versions = event['device']['runtimeVersions']
        self.assertEqual(runtime_versions['bottle'], '0.12.18')
        assert 'environment' not in event['metaData']

    def test_enable_environment(self):
        bugsnag.configure(send_environment=True)

        @route('/beans')
        def index():
            raise Exception('oh no!')

        app = bottle.app()
        app.catchall = False
        app = TestApp(BugsnagMiddleware(app))

        self.assertRaises(Exception, lambda: app.get('/beans'))
        self.assertEqual(1, len(self.server.received))
        payload = self.server.received[0]['json_body']
        metadata = payload['events'][0]['metaData']
        self.assertEqual(metadata['environment']['PATH_INFO'], '/beans')

    def test_template_error(self):
        @route('/berries/<variety>')
        def index(variety):
            return template('{{type1}} {{type2}}', type1=variety)

        app = bottle.app()
        app.catchall = False

# Path: bugsnag/wsgi/middleware.py
# class BugsnagMiddleware:
#     """
#     Notifies Bugsnag on any unhandled exception that happens while processing
#     a request in your application.
# 
#     This middleware should be installed before any middlewares that catch
#     the exception and render an error messae.
#     """
# 
#     def __init__(self, application):
#         middleware = bugsnag.configure().internal_middleware
#         if bottle_present:
#             bugsnag.configure().runtime_versions['bottle'] = bottle.__version__
#         middleware.before_notify(add_wsgi_request_data_to_notification)
#         self.application = application
# 
#     def __call__(self, environ, start_response):
#         return WrappedWSGIApp(self.application, environ, start_response)
# 
# Path: tests/utils.py
# class IntegrationTest(unittest.TestCase):
# 
#     @classmethod
#     def setUpClass(cls):
#         cls.server = FakeBugsnagServer()
# 
#     def setUp(self):
#         self.server.received = []
# 
#     def tearDown(self):
#         bugsnag.legacy.default_client.uninstall_sys_hook()
#         client = bugsnag.Client()
#         client.configuration.api_key = 'some key'
#         bugsnag.legacy.default_client = client
#         bugsnag.legacy.configuration = client.configuration
# 
#     @classmethod
#     def tearDownClass(cls):
#         cls.server.shutdown()
# 
#     def assertSentReportCount(self, count):
#         self.assertEqual(len(self.server.received), count)
# 
#     def assertExceptionName(self, received_index, event_index, name):
#         json_body = self.server.received[received_index]['json_body']
#         event = json_body['events'][event_index]
#         exception = event['exceptions'][0]
#         self.assertEqual(exception['errorClass'], name)
# 
#     @property
#     def sent_report_count(self) -> int:
#         return len(self.server.received)


# Path: tests/integrations/test_bottle.py
from webtest import TestApp
from bottle import route, template
from bugsnag.wsgi.middleware import BugsnagMiddleware
from tests.utils import IntegrationTest
import bottle
import bugsnag

        self.assertEqual(event['exceptions'][0]['errorClass'], 'Exception')
        self.assertEqual(event['exceptions'][0]['message'], 'oh no!')
        runtime_versions = event['device']['runtimeVersions']
        self.assertEqual(runtime_versions['bottle'], '0.12.18')
        assert 'environment' not in event['metaData']

    def test_enable_environment(self):
        bugsnag.configure(send_environment=True)

        @route('/beans')
        def index():
            raise Exception('oh no!')

        app = bottle.app()
        app.catchall = False
        app = TestApp(BugsnagMiddleware(app))

        self.assertRaises(Exception, lambda: app.get('/beans'))
        self.assertEqual(1, len(self.server.received))
        payload = self.server.received[0]['json_body']
        metadata = payload['events'][0]['metaData']
        self.assertEqual(metadata['environment']['PATH_INFO'], '/beans')

    def test_template_error(self):
        @route('/berries/<variety>')
        def index(variety):
            return template('{{type1}} {{type2}}', type1=variety)

        app = bottle.app()
        app.catchall = False

        app = TestApp(BugsnagMiddleware(app))