Browse Source

more unit tests

pull/1540/head
Miguel Grinberg 6 months ago
parent
commit
70f9390057
Failed to extract signature
  1. 117
      tests/async/test_pubsub_manager.py
  2. 27
      tests/common/test_pubsub_manager.py

117
tests/async/test_pubsub_manager.py

@ -374,6 +374,20 @@ class TestAsyncPubSubManager:
) )
async def test_handle_emit(self): async def test_handle_emit(self):
with mock.patch.object(
async_manager.AsyncManager, 'emit'
) as super_emit:
await self.pm._handle_emit({'event': 'foo', 'data': ['bar']})
super_emit.assert_awaited_once_with(
'foo',
'bar',
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
async def test_handle_legacy_emit(self):
with mock.patch.object( with mock.patch.object(
async_manager.AsyncManager, 'emit' async_manager.AsyncManager, 'emit'
) as super_emit: ) as super_emit:
@ -388,6 +402,37 @@ class TestAsyncPubSubManager:
) )
async def test_handle_emit_binary(self): async def test_handle_emit_binary(self):
with mock.patch.object(
async_manager.AsyncManager, 'emit'
) as super_emit:
await self.pm._handle_emit({
'event': 'foo',
'binary': True,
'data': [[{'_placeholder': True, 'num': 0}], 'YmFy'],
})
super_emit.assert_awaited_once_with(
'foo',
b'bar',
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
await self.pm._handle_emit({
'event': 'foo',
'binary': True,
'data': [[{'foo': {'_placeholder': True, 'num': 0}}], 'YmFy'],
})
super_emit.assert_awaited_with(
'foo',
{'foo': b'bar'},
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
async def test_handle_legacy_emit_binary(self):
with mock.patch.object( with mock.patch.object(
async_manager.AsyncManager, 'emit' async_manager.AsyncManager, 'emit'
) as super_emit: ) as super_emit:
@ -418,6 +463,78 @@ class TestAsyncPubSubManager:
callback=None, callback=None,
) )
async def test_handle_emit_list(self):
with mock.patch.object(
async_manager.AsyncManager, 'emit'
) as super_emit:
await self.pm._handle_emit({'event': 'foo', 'data': [[1, 'two']]})
super_emit.assert_awaited_once_with(
'foo',
[1, 'two'],
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
await self.pm._handle_emit({
'event': 'foo',
'binary': True,
'data': [
[[1, {'_placeholder': True, 'num': 0}, 'three']], 'dHdv'
]
})
super_emit.assert_awaited_with(
'foo',
[1, b'two', 'three'],
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
async def test_handle_emit_no_arguments(self):
with mock.patch.object(
async_manager.AsyncManager, 'emit'
) as super_emit:
await self.pm._handle_emit({'event': 'foo', 'data': []})
super_emit.assert_awaited_once_with(
'foo',
(),
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
async def test_handle_emit_multiple_arguments(self):
with mock.patch.object(
async_manager.AsyncManager, 'emit'
) as super_emit:
await self.pm._handle_emit({'event': 'foo', 'data': [1, 'two']})
super_emit.assert_awaited_once_with(
'foo',
(1, 'two'),
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
await self.pm._handle_emit({
'event': 'foo',
'binary': True,
'data': [
[1, {'_placeholder': True, 'num': 0}, 'three'], 'dHdv'
]
})
super_emit.assert_awaited_with(
'foo',
(1, b'two', 'three'),
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
async def test_handle_emit_with_namespace(self): async def test_handle_emit_with_namespace(self):
with mock.patch.object( with mock.patch.object(
async_manager.AsyncManager, 'emit' async_manager.AsyncManager, 'emit'

27
tests/common/test_pubsub_manager.py

@ -466,6 +466,33 @@ class TestPubSubManager:
callback=None, callback=None,
) )
def test_handle_emit_list(self):
with mock.patch.object(manager.Manager, 'emit') as super_emit:
self.pm._handle_emit({'event': 'foo', 'data': [[1, 'two']]})
super_emit.assert_called_once_with(
'foo',
[1, 'two'],
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
self.pm._handle_emit({
'event': 'foo',
'binary': True,
'data': [
[[1, {'_placeholder': True, 'num': 0}, 'three']], 'dHdv'
],
})
super_emit.assert_called_with(
'foo',
[1, b'two', 'three'],
namespace=None,
room=None,
skip_sid=None,
callback=None,
)
def test_handle_emit_no_arguments(self): def test_handle_emit_no_arguments(self):
with mock.patch.object(manager.Manager, 'emit') as super_emit: with mock.patch.object(manager.Manager, 'emit') as super_emit:
self.pm._handle_emit({'event': 'foo', 'data': []}) self.pm._handle_emit({'event': 'foo', 'data': []})

Loading…
Cancel
Save