Example #1
0
async def world_communicator(client_id=None, named=True, token=None):
    communicator = WebsocketCommunicator(application, "/ws/world/sample/")
    await communicator.connect()
    if token:
        await communicator.send_json_to(["authenticate", {"token": token}])

    else:
        await communicator.send_json_to(
            ["authenticate", {
                "client_id": client_id or str(uuid.uuid4())
            }])
    response = await communicator.receive_json_from()
    assert response[0] == "authenticated", response
    communicator.context = response[1]
    assert "world.config" in response[1], response
    if named:
        await communicator.send_json_to(
            ["user.update", 123, {
                "profile": {
                    "display_name": "Foo Fighter"
                }
            }])
        await communicator.receive_json_from()
    try:
        yield communicator
    finally:
        await communicator.disconnect()
Example #2
0
 def get_communicator(user=None, token=None):
     user = AvatarFactory().user if user is None else user
     token = Token.objects.create(user=user).key if token is None else token
     communicator = WebsocketCommunicator(
         application=application,
         path=f'/ws/notification/',
         subprotocols=['access_token', token])
     communicator.context = {'user': user, 'token': token}
     return communicator
Example #3
0
 def get_communicator(user=None, room=None, token=None):
     user = AvatarFactory().user if user is None else user
     room = RoomFactory().pk if room is None else room
     token = Token.objects.create(user=user).key if token is None else token
     communicator = WebsocketCommunicator(
         application=application,
         path=f'/ws/chat/{room}/',
         subprotocols=['access_token', token])
     communicator.scope['url_route'] = {'kwargs': {'room_id': room}}
     communicator.context = {'user': user, 'room': room, 'token': token}
     return communicator
Example #4
0
async def world_communicator(client_id=None, named=True):
    communicator = WebsocketCommunicator(application, "/ws/world/sample/")
    await communicator.connect()
    await communicator.send_json_to(
        ["authenticate", {
            "client_id": client_id or str(uuid.uuid4())
        }])
    response = await communicator.receive_json_from()
    assert response[0] == "authenticated", response
    communicator.context = response[1]
    assert "world.config" in response[1], response
    try:
        yield communicator
    finally:
        await communicator.disconnect()