@@ -108,6 +108,11 @@ def get_request_event2(data):
108108socketio .on_event ('yet another custom event' , get_request_event2 )
109109
110110
111+ @socketio .on ('*' )
112+ def catch_all (event , data ):
113+ emit ('my custom response' , (event , data ))
114+
115+
111116@socketio .on ('my custom namespace event' , namespace = '/test' )
112117def on_custom_event_test (data ):
113118 emit ('my custom namespace response' , data , namespace = '/test' )
@@ -421,16 +426,6 @@ def test_send_json_namespace(self):
421426 self .assertEqual (len (received ), 1 )
422427 self .assertEqual (received [0 ]['args' ]['a' ], 'b' )
423428
424- def test_send_catch_all_namespace (self ):
425- client = socketio .test_client (app , namespace = '/test' )
426- client .get_received ('/test' )
427- client .emit ('wildcard' , {'a' : 'b' }, namespace = '/test' )
428- received = client .get_received ('/test' )
429- self .assertEqual (len (received ), 1 )
430- self .assertEqual (len (received [0 ]['args' ]), 1 )
431- self .assertEqual (received [0 ]['name' ], 'my custom response' )
432- self .assertEqual (received [0 ]['args' ][0 ]['a' ], 'b' )
433-
434429 def test_emit (self ):
435430 client = socketio .test_client (app , auth = {'foo' : 'bar' })
436431 client .get_received ()
@@ -451,6 +446,27 @@ def test_emit_binary(self):
451446 self .assertEqual (received [0 ]['name' ], 'my custom response' )
452447 self .assertEqual (received [0 ]['args' ][0 ]['a' ], b'\x01 \x02 \x03 ' )
453448
449+ def test_emit_catch_all_event (self ):
450+ client = socketio .test_client (app , auth = {'foo' : 'bar' })
451+ client .get_received ()
452+ client .emit ('random event' , {'foo' : 'bar' })
453+ received = client .get_received ()
454+ self .assertEqual (len (received ), 1 )
455+ self .assertEqual (len (received [0 ]['args' ]), 2 )
456+ self .assertEqual (received [0 ]['name' ], 'my custom response' )
457+ self .assertEqual (received [0 ]['args' ][0 ], 'random event' )
458+ self .assertEqual (received [0 ]['args' ][1 ], {'foo' : 'bar' })
459+
460+ def test_send_catch_all_namespace (self ):
461+ client = socketio .test_client (app , namespace = '/test' )
462+ client .get_received ('/test' )
463+ client .emit ('wildcard' , {'a' : 'b' }, namespace = '/test' )
464+ received = client .get_received ('/test' )
465+ self .assertEqual (len (received ), 1 )
466+ self .assertEqual (len (received [0 ]['args' ]), 1 )
467+ self .assertEqual (received [0 ]['name' ], 'my custom response' )
468+ self .assertEqual (received [0 ]['args' ][0 ]['a' ], 'b' )
469+
454470 def test_request_event_data (self ):
455471 client = socketio .test_client (app , auth = {'foo' : 'bar' })
456472 client .get_received ()
0 commit comments