mirror of https://github.com/encode/starlette.git
Update test_client doc from README.md
This commit is contained in:
parent
1f6fabc5e1
commit
774e78d269
|
@ -3,7 +3,8 @@ The test client allows you to make requests against your ASGI application,
|
||||||
using the `requests` library.
|
using the `requests` library.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from starlette import HTMLResponse, TestClient
|
from starlette.response import HTMLResponse
|
||||||
|
from starlette.testclient import TestClient
|
||||||
|
|
||||||
|
|
||||||
class App:
|
class App:
|
||||||
|
@ -51,7 +52,7 @@ class App:
|
||||||
|
|
||||||
def test_app():
|
def test_app():
|
||||||
client = TestClient(App)
|
client = TestClient(App)
|
||||||
with client.wsconnect('/') as session:
|
with client.websocket_connect('/') as session:
|
||||||
data = session.receive_text()
|
data = session.receive_text()
|
||||||
assert data == 'Hello, world!'
|
assert data == 'Hello, world!'
|
||||||
```
|
```
|
||||||
|
@ -65,10 +66,16 @@ always raised by the test client.
|
||||||
|
|
||||||
#### Establishing a test session
|
#### 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.
|
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
|
#### Receiving data
|
||||||
|
|
||||||
* `.receive_text()` - Wait for incoming text sent by the application and return it.
|
* `.receive_text()` - Wait for incoming text sent by the application and return it.
|
||||||
|
|
Loading…
Reference in New Issue