def setUp(self): mock_server = mock.MagicMock() mock_server._emit_internal = AsyncMock() self.pm = asyncio_pubsub_manager.AsyncPubSubManager() self.pm._publish = AsyncMock() self.pm.set_server(mock_server) self.pm.initialize()
def test_write_only_init(self): mock_server = mock.MagicMock() pm = asyncio_pubsub_manager.AsyncPubSubManager(write_only=True) pm.set_server(mock_server) pm.initialize() assert pm.channel == 'socketio' assert len(pm.host_id) == 32 assert pm.server.start_background_task.call_count == 0
def test_write_only_init(self): mock_server = mock.MagicMock() pm = asyncio_pubsub_manager.AsyncPubSubManager(write_only=True) pm.set_server(mock_server) pm.initialize() self.assertEqual(pm.channel, 'socketio') self.assertEqual(len(pm.host_id), 32) self.assertEqual(pm.server.start_background_task.call_count, 0)
def setUp(self): id = 0 def generate_id(): nonlocal id id += 1 return str(id) mock_server = mock.MagicMock() mock_server.eio.generate_id = generate_id mock_server._emit_internal = AsyncMock() mock_server.disconnect = AsyncMock() self.pm = asyncio_pubsub_manager.AsyncPubSubManager() self.pm._publish = AsyncMock() self.pm.set_server(mock_server) self.pm.host_id = '123456' self.pm.initialize()
def test_custom_init(self): pubsub = asyncio_pubsub_manager.AsyncPubSubManager(channel='foo') assert pubsub.channel == 'foo' assert len(pubsub.host_id) == 32
def test_emit_with_callback_without_server(self): standalone_pm = asyncio_pubsub_manager.AsyncPubSubManager() with pytest.raises(RuntimeError): _run(standalone_pm.emit('foo', 'bar', callback='cb'))
def test_custom_init(self): pubsub = asyncio_pubsub_manager.AsyncPubSubManager(channel='foo') self.assertEqual(pubsub.channel, 'foo') self.assertEqual(len(pubsub.host_id), 32)