Update test_client doc from README.md

This commit is contained in:
Jeff Buttars 2018-08-28 08:18:17 -06:00
parent 1f6fabc5e1
commit 774e78d269
1 changed files with 10 additions and 3 deletions

View File

@ -3,7 +3,8 @@ The test client allows you to make requests against your ASGI application,
using the `requests` library.
```python
from starlette import HTMLResponse, TestClient
from starlette.response import HTMLResponse
from starlette.testclient import TestClient
class App:
@ -51,7 +52,7 @@ class App:
def test_app():
client = TestClient(App)
with client.wsconnect('/') as session:
with client.websocket_connect('/') as session:
data = session.receive_text()
assert data == 'Hello, world!'
```
@ -65,10 +66,16 @@ always raised by the test client.
#### Establishing a test session
* `.wsconnect(url, subprotocols=None, **options)` - Takes the same set of arguments as `requests.get()`.
* `.websocket_connect(url, subprotocols=None, **options)` - Takes the same set of arguments as `requests.get()`.
May raise `starlette.websockets.Disconnect` if the application does not accept the websocket connection.
#### Sending data
* `.send_text(data)` - Send the given text to the application.
* `.send_bytes(data)` - Send the given bytes to the application.
* `.send_json(data)` - Send the given data to the application.
#### Receiving data
* `.receive_text()` - Wait for incoming text sent by the application and return it.