Comments (4)
Hi @otsuka,
Feel free to open a PR with these features if you want :) but if you prefer, I can do it myself during the weekend.
from async-asgi-testclient.
@masipcat
I will appreciate it if you would do it.
from async-asgi-testclient.
In my use case, I have to write tests dealing with multiple users like chat app.
So it might be convenient to be able to set cookies in each WebSocketSession instance in addition to inheriting cookies from TestClient.
It would be useful if we could set cookies as easily as the code below (like aiohttp.ClientSession)
async with TestClient(app): # invoking 'startup' only once
# I don't use `async with WebSocketSession` to avoid deep nesting when handling multiple ws connections
ws1 = WebSocketSession(app, ws_endpoint, cookies={'sessionid': 'xxxxxxxxxxxxxx'})
ws2 = WebSocketSession(app, ws_endpoint, cookies={'sessionid': 'yyyyyyyyyyyyyy'})
await ws1.connect()
await ws2.connect()
await ws1.send_str('Hello') # BTW, send_text() is better for consistency, isn't it?
text = await ws2.receive_text()
assert text == 'Hello'
await ws2.close()
await ws1.close()
from async-asgi-testclient.
Version 1.4.0 released! I added the argument 'cookies' to websocket_connect()
(and WebSocketSession
as well) and I renamed ws.send_str()
to ws.send_text()
.
from async-asgi-testclient.
Related Issues (20)
- WebSocket connection with query params - failed HOT 4
- Better way to provide headers for each request HOT 3
- Add multipart support
- File uploading error HOT 5
- Compatibilty with aiohttp.ClientSession? HOT 4
- [odd] issue trying to `poetry add` this package HOT 2
- No way to add multiple files with the same name HOT 2
- Support for aridane HOT 1
- WebSocket connection scope's subprotocols not properly constructed
- Request `Cookie` header is invalid
- Bug: websocket scope error HOT 1
- Allow setting the full request URL including a hostname / port
- Cannot use `wss://` as the scheme for WebSocket tests
- Issues with compliance to the ASGI specification HOT 1
- client can't handle redirect of absolute paths HOT 1
- Client unable to handle websocket connection rejections HOT 2
- streaming not working with newer versions of starlette HOT 1
- [feature request] trio support
- TestClient calls wrong methd when fastapi.APIRouter().add_api_router() is used to setup the router
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-asgi-testclient.