# Path: honeybadger/contrib/fastapi.py
# class HoneybadgerRoute(APIRoute):
#     def get_route_handler(self) -> Callable:
#         original_route_handler = super().get_route_handler()
# 
#         async def custom_route_handler(request: Request):
#             try:
#                 return await original_route_handler(request)
#             except exceptions.HTTPException as exc:
#                 raise exc from None
#             except Exception as exc:
#                 body = await request.body()
#                 scope = dict(request)
#                 scope["body"] = body
#                 honeybadger.notify(exception=exc, context=asgi._as_context(scope))
#                 raise exc from None
#             finally:
#                 honeybadger.reset_context()
#         return custom_route_handler


import unittest
import aiounittest
import mock
from honeybadger.contrib.fastapi import HoneybadgerRoute
from fastapi import FastAPI
from fastapi.testclient import TestClient


class FastAPITestCase(unittest.TestCase):
    def setUp(self):
        app = FastAPI()
        app.router.route_class = HoneybadgerRoute

        @app.get("/ok")
        def ok_route():
            return "ok"

        @app.get("/ko")
        def ko_route():
            return 1 / 0

        self.client = TestClient(app, raise_server_exceptions=False)

    @mock.patch("honeybadger.contrib.fastapi.honeybadger")
    def test_should_not_notify_on_ok_route(self, hb):
        response = self.client.get("/ok")
        self.assertEqual(response.status_code, 200)

# Path: honeybadger/contrib/fastapi.py
# class HoneybadgerRoute(APIRoute):
#     def get_route_handler(self) -> Callable:
#         original_route_handler = super().get_route_handler()
# 
#         async def custom_route_handler(request: Request):
#             try:
#                 return await original_route_handler(request)
#             except exceptions.HTTPException as exc:
#                 raise exc from None
#             except Exception as exc:
#                 body = await request.body()
#                 scope = dict(request)
#                 scope["body"] = body
#                 honeybadger.notify(exception=exc, context=asgi._as_context(scope))
#                 raise exc from None
#             finally:
#                 honeybadger.reset_context()
#         return custom_route_handler


# Path: honeybadger/tests/contrib/test_fastapi.py
import unittest
import aiounittest
import mock
from honeybadger.contrib.fastapi import HoneybadgerRoute
from fastapi import FastAPI
from fastapi.testclient import TestClient



class FastAPITestCase(unittest.TestCase):
    def setUp(self):
        app = FastAPI()
        app.router.route_class = HoneybadgerRoute

        @app.get("/ok")
        def ok_route():
            return "ok"

        @app.get("/ko")
        def ko_route():
            return 1 / 0

        self.client = TestClient(app, raise_server_exceptions=False)

    @mock.patch("honeybadger.contrib.fastapi.honeybadger")
    def test_should_not_notify_on_ok_route(self, hb):
        response = self.client.get("/ok")
        self.assertEqual(response.status_code, 200)

        hb.notify.assert_not_called()