From b9e1ed7d7e2a60752434a6493be429040d502c75 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Wed, 3 Feb 2021 23:18:28 +0100 Subject: [PATCH] added test for web socket authentication --- src/paperless/tests/test_websockets.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/paperless/tests/test_websockets.py diff --git a/src/paperless/tests/test_websockets.py b/src/paperless/tests/test_websockets.py new file mode 100644 index 000000000..e5745ce77 --- /dev/null +++ b/src/paperless/tests/test_websockets.py @@ -0,0 +1,25 @@ +from unittest import mock + +from channels.testing import WebsocketCommunicator +from django.test import TestCase + +from paperless.asgi import application + + +class TestWebSockets(TestCase): + + async def test_no_auth(self): + communicator = WebsocketCommunicator(application, "/ws/status/") + connected, subprotocol = await communicator.connect() + self.assertFalse(connected) + await communicator.disconnect() + + @mock.patch("paperless.consumers.StatusConsumer._authenticated") + async def test_auth(self, _authenticated): + _authenticated.return_value = True + + communicator = WebsocketCommunicator(application, "/ws/status/") + connected, subprotocol = await communicator.connect() + self.assertTrue(connected) + + await communicator.disconnect()