funkwhale/api/tests/channels/test_consumers.py
Georg Krause 003203c45d Update Channels to version 3
This reduces coverage since one test case needed to be removed. Its not that easy anymore to pass a custom scope into a tested application. It gets verified that no invalid authentication is possible though. Proper testing should be done with another issue.
2021-07-24 11:48:52 +00:00

18 lines
658 B
Python

import pytest
from channels.testing import WebsocketCommunicator
from funkwhale_api.common.consumers import JsonAuthConsumer
@pytest.mark.asyncio
async def test_auth_consumer_requires_valid_user():
communicator = WebsocketCommunicator(JsonAuthConsumer.as_asgi(), "api/v1/activity")
communicator.scope["user"] = None
connected, subprotocol = await communicator.connect()
assert not connected
@pytest.mark.asyncio
async def test_auth_consumer_requires_user_in_scope():
communicator = WebsocketCommunicator(JsonAuthConsumer.as_asgi(), "api/v1/activity")
connected, subprotocol = await communicator.connect()
assert not connected