@@ -34,6 +34,7 @@ class TestAsyncPubSubManager(unittest.TestCase):
3434 def setUp (self ):
3535 mock_server = mock .MagicMock ()
3636 mock_server ._emit_internal = AsyncMock ()
37+ mock_server .disconnect = AsyncMock ()
3738 self .pm = asyncio_pubsub_manager .AsyncPubSubManager ()
3839 self .pm ._publish = AsyncMock ()
3940 self .pm .set_server (mock_server )
@@ -115,6 +116,11 @@ def test_emit_with_ignore_queue(self):
115116 self .pm .server ._emit_internal .mock .assert_called_once_with (
116117 '123' , 'foo' , 'bar' , '/' , None )
117118
119+ def test_disconnect (self ):
120+ _run (self .pm .disconnect ('123' , '/foo' ))
121+ self .pm ._publish .mock .assert_called_once_with (
122+ {'method' : 'disconnect' , 'sid' : '123' , 'namespace' : '/foo' })
123+
118124 def test_close_room (self ):
119125 _run (self .pm .close_room ('foo' ))
120126 self .pm ._publish .mock .assert_called_once_with (
@@ -142,7 +148,7 @@ def test_handle_emit_with_namespace(self):
142148 self .pm , 'foo' , 'bar' , namespace = '/baz' , room = None ,
143149 skip_sid = None , callback = None )
144150
145- def test_handle_emiti_with_room (self ):
151+ def test_handle_emit_with_room (self ):
146152 with mock .patch .object (asyncio_manager .AsyncManager , 'emit' ,
147153 new = AsyncMock ()) as super_emit :
148154 _run (self .pm ._handle_emit ({'event' : 'foo' , 'data' : 'bar' ,
@@ -216,6 +222,12 @@ def test_handle_callback_missing_args(self):
216222 'host_id' : host_id }))
217223 self .assertEqual (trigger .mock .call_count , 0 )
218224
225+ def test_handle_disconnect (self ):
226+ _run (self .pm ._handle_disconnect ({'method' : 'disconnect' , 'sid' : '123' ,
227+ 'namespace' : '/foo' }))
228+ self .pm .server .disconnect .mock .assert_called_once_with (
229+ sid = '123' , namespace = '/foo' , ignore_queue = True )
230+
219231 def test_handle_close_room (self ):
220232 with mock .patch .object (asyncio_manager .AsyncManager , 'close_room' ,
221233 new = AsyncMock ()) as super_close_room :
@@ -236,13 +248,15 @@ def test_handle_close_room_with_namespace(self):
236248 def test_background_thread (self ):
237249 self .pm ._handle_emit = AsyncMock ()
238250 self .pm ._handle_callback = AsyncMock ()
251+ self .pm ._handle_disconnect = AsyncMock ()
239252 self .pm ._handle_close_room = AsyncMock ()
240253
241254 def messages ():
242255 import pickle
243256 yield {'method' : 'emit' , 'value' : 'foo' }
244257 yield {'missing' : 'method' }
245258 yield '{"method": "callback", "value": "bar"}'
259+ yield {'method' : 'disconnect' , 'sid' : '123' , 'namespace' : '/foo' }
246260 yield {'method' : 'bogus' }
247261 yield pickle .dumps ({'method' : 'close_room' , 'value' : 'baz' })
248262 yield 'bad json'
@@ -258,5 +272,7 @@ def messages():
258272 {'method' : 'emit' , 'value' : 'foo' })
259273 self .pm ._handle_callback .mock .assert_called_once_with (
260274 {'method' : 'callback' , 'value' : 'bar' })
275+ self .pm ._handle_disconnect .mock .assert_called_once_with (
276+ {'method' : 'disconnect' , 'sid' : '123' , 'namespace' : '/foo' })
261277 self .pm ._handle_close_room .mock .assert_called_once_with (
262278 {'method' : 'close_room' , 'value' : 'baz' })
0 commit comments