outposts: add ack and disconnect tests

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-11-16 09:34:37 +01:00
parent e7dc763612
commit 425b87a6d0
2 changed files with 21 additions and 1 deletions

View file

@ -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))

View file

@ -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()