From 08411f99014d3680f1e2591b1e9ff1c5bfd0a5f5 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 5 Sep 2023 09:26:16 +0100 Subject: [PATCH] Test client fixes to support dependency changes (Fixes #2006) --- src/flask_socketio/test_client.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/flask_socketio/test_client.py b/src/flask_socketio/test_client.py index f930c97..0603d77 100644 --- a/src/flask_socketio/test_client.py +++ b/src/flask_socketio/test_client.py @@ -59,6 +59,23 @@ class SocketIOTestClient(object): elif pkt.packet_type in [packet.DISCONNECT, packet.CONNECT_ERROR]: client.connected[pkt.namespace or '/'] = False + _current_packet = None + + def _mock_send_eio_packet(eio_sid, eio_pkt): + nonlocal _current_packet + if _current_packet is not None: + _current_packet.add_attachment(eio_pkt.data) + if _current_packet.attachment_count == \ + len(_current_packet.attachments): + _mock_send_packet(eio_sid, _current_packet) + _current_packet = None + else: + pkt = packet.Packet(encoded_packet=eio_pkt.data) + if pkt.attachment_count == 0: + _mock_send_packet(eio_sid, pkt) + else: + _current_packet = pkt + self.app = app self.flask_test_client = flask_test_client self.eio_sid = uuid.uuid4().hex @@ -69,6 +86,7 @@ class SocketIOTestClient(object): self.queue = [] self.acks = None socketio.server._send_packet = _mock_send_packet + socketio.server._send_eio_packet = _mock_send_eio_packet socketio.server.environ[self.eio_sid] = {} socketio.server.async_handlers = False # easier to test when socketio.server.eio.async_handlers = False # events are sync