-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(asgi+starlette): adapt tests to OTel usage.
Signed-off-by: Paulo Vital <[email protected]>
- Loading branch information
Showing
12 changed files
with
511 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ exclude_lines = | |
pragma: no cover | ||
if TYPE_CHECKING: | ||
except ImportError: | ||
except Exception: | ||
except Exception as exc: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,40 @@ | ||
# (c) Copyright IBM Corp. 2021 | ||
# (c) Copyright Instana Inc. 2020 | ||
|
||
import os | ||
|
||
from starlette.applications import Starlette | ||
from starlette.responses import PlainTextResponse | ||
from starlette.routing import Route, Mount, WebSocketRoute | ||
from starlette.routing import Mount, Route, WebSocketRoute | ||
from starlette.staticfiles import StaticFiles | ||
|
||
import os | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def homepage(request): | ||
return PlainTextResponse('Hello, world!') | ||
return PlainTextResponse("Hello, world!") | ||
|
||
|
||
def user(request): | ||
user_id = request.path_params['user_id'] | ||
return PlainTextResponse('Hello, user id %s!' % user_id) | ||
user_id = request.path_params["user_id"] | ||
return PlainTextResponse("Hello, user id %s!" % user_id) | ||
|
||
|
||
async def websocket_endpoint(websocket): | ||
await websocket.accept() | ||
await websocket.send_text('Hello, websocket!') | ||
await websocket.send_text("Hello, websocket!") | ||
await websocket.close() | ||
|
||
|
||
def startup(): | ||
print('Ready to go') | ||
print("Ready to go") | ||
|
||
|
||
routes = [ | ||
Route('/', homepage), | ||
Route('/users/{user_id}', user), | ||
WebSocketRoute('/ws', websocket_endpoint), | ||
Mount('/static', StaticFiles(directory=dir_path + "/static")), | ||
Route("/", homepage), | ||
Route("/users/{user_id}", user), | ||
WebSocketRoute("/ws", websocket_endpoint), | ||
Mount("/static", StaticFiles(directory=dir_path + "/static")), | ||
] | ||
|
||
starlette_server = Starlette(debug=True, routes=routes, on_startup=[startup]) | ||
starlette_server = Starlette(debug=True, routes=routes, on_startup=[startup]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# (c) Copyright IBM Corp. 2024 | ||
|
||
import os | ||
|
||
from starlette.applications import Starlette | ||
from starlette.middleware import Middleware | ||
from starlette.middleware.trustedhost import TrustedHostMiddleware | ||
from starlette.responses import PlainTextResponse | ||
from starlette.routing import Route | ||
|
||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def homepage(request): | ||
return PlainTextResponse("Hello, world!") | ||
|
||
|
||
def five_hundred(request): | ||
return PlainTextResponse("Something went wrong!", status_code=500) | ||
|
||
|
||
def startup(): | ||
print("Ready to go") | ||
|
||
|
||
routes = [ | ||
Route("/", homepage), | ||
Route("/five", five_hundred), | ||
] | ||
|
||
starlette_server = Starlette( | ||
debug=True, | ||
routes=routes, | ||
on_startup=[startup], | ||
middleware=[ | ||
Middleware( | ||
TrustedHostMiddleware, | ||
allowed_hosts=["*"], | ||
), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.