From 425b87a6d028e9f4ed094d825be61bb0b85073ef Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 16 Nov 2021 09:34:37 +0100 Subject: [PATCH] outposts: add ack and disconnect tests Signed-off-by: Jens Langhammer --- authentik/outposts/channels.py | 2 +- authentik/outposts/tests/test_ws.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/authentik/outposts/channels.py b/authentik/outposts/channels.py index 58945e72e..c781e04eb 100644 --- a/authentik/outposts/channels.py +++ b/authentik/outposts/channels.py @@ -126,7 +126,7 @@ class OutpostConsumer(AuthJsonConsumer): self.send_json(asdict(response)) # pylint: disable=unused-argument - def event_update(self, event): + def event_update(self, event): # pragma: no cover """Event handler which is called by post_save signals, Send update instruction""" self.send_json( asdict(WebsocketMessage(instruction=WebsocketMessageInstruction.TRIGGER_UPDATE)) diff --git a/authentik/outposts/tests/test_ws.py b/authentik/outposts/tests/test_ws.py index 6b4d04c2d..982fe515a 100644 --- a/authentik/outposts/tests/test_ws.py +++ b/authentik/outposts/tests/test_ws.py @@ -75,3 +75,23 @@ class TestOutpostWS(TransactionTestCase): self.assertEqual( response, asdict(WebsocketMessage(instruction=WebsocketMessageInstruction.ACK, args={})) ) + await communicator.disconnect() + + async def test_send_ack(self): + """Test sending of ACK""" + communicator = WebsocketCommunicator( + URLRouter(websocket.websocket_urlpatterns), + f"/ws/outpost/{self.outpost.pk}/", + {b"authorization": f"Bearer {self.token}".encode()}, + ) + connected, _ = await communicator.connect() + self.assertTrue(connected) + await communicator.send_json_to( + asdict( + WebsocketMessage( + instruction=WebsocketMessageInstruction.ACK, + args={}, + ) + ) + ) + await communicator.disconnect()