File
Blob: src/workerd/server/tests/python/vendor_pkg_tests/existing_dedicated_fastapi.py
| 1 | import fastapi |
| 2 | from fastapi import FastAPI |
| 3 | from workers import WorkerEntrypoint |
| 4 | |
| 5 | app = FastAPI() |
| 6 | |
| 7 | |
| 8 | @app.get("/") |
| 9 | async def root(): |
| 10 | message = "This is an example of FastAPI" |
| 11 | return {"message": message} |
| 12 | |
| 13 | |
| 14 | class Default(WorkerEntrypoint): |
| 15 | async def fetch(self, request): |
| 16 | import asgi |
| 17 | |
| 18 | return await asgi.fetch(app, request.js_object, self.env) |
| 19 | |
| 20 | async def test(self, a, b, c): |
| 21 | assert fastapi.__version__ |
| 22 | # The dedicated snapshot we are testing contains source code which is different to |
| 23 | # below. It will pass the test instead. So we fail this script to show that the snapshot |
| 24 | # wasn't loaded correctly. |
| 25 | print("FastAPI dedicated snapshot wasn't loaded") |
| 26 | raise AssertionError("FastAPI dedicated snapshot wasn't loaded") |