-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reusable client tests and refactor (#74)
in python 3.12, its required to close the writer to stop the server. unless its hangs on `wait_closed`
- Loading branch information
Showing
2 changed files
with
30 additions
and
3 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
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,26 @@ | ||
import pytest | ||
from sanic import Sanic, response | ||
|
||
from sanic_testing.reusable import ReusableClient | ||
|
||
|
||
@pytest.fixture | ||
def reusable_app(): | ||
sanic_app = Sanic(__name__) | ||
|
||
@sanic_app.get("/") | ||
def basic(request): | ||
return response.text("foo") | ||
|
||
return sanic_app | ||
|
||
|
||
@pytest.mark.asyncio | ||
def test_basic_asgi_client(reusable_app): | ||
client = ReusableClient(reusable_app) | ||
with client: | ||
request, response = client.get("/") | ||
|
||
assert request.method.lower() == "get" | ||
assert response.body == b"foo" | ||
assert response.status == 200 |