Skip to content

Commit 13b20ca

Browse files
unit tests
1 parent 7c82a50 commit 13b20ca

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

tests/async/test_pubsub_manager.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import pytest
77

8+
from engineio.packet import Packet as EIOPacket
89
from socketio import async_manager
910
from socketio import async_pubsub_manager
11+
from socketio import async_server
1012
from socketio import packet
1113

1214

@@ -846,3 +848,14 @@ async def messages():
846848
self.pm._handle_emit.assert_awaited_with(
847849
{'method': 'emit', 'value': 'bar', 'host_id': 'x'}
848850
)
851+
852+
def test_custom_json(self):
853+
saved_json = packet.Packet.json
854+
855+
cm = async_pubsub_manager.AsyncPubSubManager(json='foo')
856+
assert cm.json == 'foo'
857+
async_server.AsyncServer(json='bar', client_manager=cm)
858+
assert cm.json == 'bar'
859+
860+
packet.Packet.json = saved_json
861+
EIOPacket.json = saved_json

tests/async/test_redis_manager.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import redis
33
import valkey
44

5-
from socketio import async_redis_manager
5+
from engineio.packet import Packet as EIOPacket
6+
from socketio import async_redis_manager, AsyncServer
67
from socketio.async_redis_manager import AsyncRedisManager
8+
from socketio.packet import Packet
79

810

911
class TestAsyncRedisManager:
@@ -109,3 +111,14 @@ def test_valkey_connect(self):
109111
assert isinstance(c.redis, valkey.asyncio.Valkey)
110112

111113
async_redis_manager.aioredis = saved_redis
114+
115+
def test_custom_json(self):
116+
saved_json = Packet.json
117+
118+
cm = AsyncRedisManager('redis://', json='foo')
119+
assert cm.json == 'foo'
120+
AsyncServer(json='bar', client_manager=cm)
121+
assert cm.json == 'bar'
122+
123+
Packet.json = saved_json
124+
EIOPacket.json = saved_json

tests/common/test_pubsub_manager.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
import pytest
77

8+
from engineio.packet import Packet as EIOPacket
89
from socketio import manager
910
from socketio import pubsub_manager
1011
from socketio import packet
12+
from socketio import server
1113

1214

1315
class TestPubSubManager:
@@ -822,3 +824,14 @@ def messages():
822824
self.pm._handle_emit.assert_called_with(
823825
{'method': 'emit', 'value': 'bar', 'host_id': 'x'}
824826
)
827+
828+
def test_custom_json(self):
829+
saved_json = packet.Packet.json
830+
831+
cm = pubsub_manager.PubSubManager(json='foo')
832+
assert cm.json == 'foo'
833+
server.Server(json='bar', client_manager=cm)
834+
assert cm.json == 'bar'
835+
836+
packet.Packet.json = saved_json
837+
EIOPacket.json = saved_json

tests/common/test_redis_manager.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import redis
33
import valkey
44

5-
from socketio import redis_manager
5+
from engineio.packet import Packet as EIOPacket
6+
from socketio import redis_manager, Server
7+
from socketio.packet import Packet
68
from socketio.redis_manager import RedisManager, parse_redis_sentinel_url
79

810

@@ -144,3 +146,14 @@ def test_sentinel_url_parser(self, rtype):
144146
'myredis',
145147
{'username': 'user', 'password': 'password', 'db': 0}
146148
)
149+
150+
def test_custom_json(self):
151+
saved_json = Packet.json
152+
153+
cm = RedisManager('redis://', json='foo')
154+
assert cm.json == 'foo'
155+
Server(json='bar', client_manager=cm)
156+
assert cm.json == 'bar'
157+
158+
Packet.json = saved_json
159+
EIOPacket.json = saved_json

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ python =
1414
[testenv]
1515
commands=
1616
pip install -e .
17-
pytest -p no:logging --timeout=60 --cov=socketio --cov-branch --cov-report=term-missing --cov-report=xml
17+
pytest -p no:logging --timeout=60 --cov=socketio --cov-branch --cov-report=term-missing --cov-report=xml {posargs}
1818
deps=
1919
simple-websocket
2020
uvicorn

0 commit comments

Comments
 (0)