Coder Social home page Coder Social logo

Comments (4)

masipcat avatar masipcat commented on August 29, 2024 1

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.

otsuka avatar otsuka commented on August 29, 2024

@masipcat
I will appreciate it if you would do it.

from async-asgi-testclient.

otsuka avatar otsuka commented on August 29, 2024

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.

masipcat avatar masipcat commented on August 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.