def test_register_handlers(): # noqa: C901 robot = WeRoBot(SESSION_STORAGE=False) for type in robot.message_types: assert hasattr(robot, type) or hasattr(robot, type.replace( '_event', '')) @robot.text def text_handler(): return "Hi" assert robot._handlers["text"] == [(text_handler, 0)] @robot.image def image_handler(message): return 'nice pic' assert robot._handlers["image"] == [(image_handler, 1)] assert robot.get_handlers("text") == [(text_handler, 0)] @robot.handler def handler(message, session): pass assert robot.get_handlers("text") == [(text_handler, 0), (handler, 2)] @robot.video def video_handler(): pass assert robot._handlers["video"] == [(video_handler, 0)] assert robot.get_handlers("video") == [(video_handler, 0), (handler, 2)] @robot.shortvideo def shortvideo_handler(): pass assert robot._handlers["shortvideo"] == [(shortvideo_handler, 0)] assert robot.get_handlers("shortvideo") == [(shortvideo_handler, 0), (handler, 2)] @robot.location def location_handler(): pass assert robot._handlers["location"] == [(location_handler, 0)] @robot.link def link_handler(): pass assert robot._handlers["link"] == [(link_handler, 0)] @robot.subscribe def subscribe_handler(): pass assert robot._handlers["subscribe_event"] == [(subscribe_handler, 0)] @robot.unsubscribe def unsubscribe_handler(): pass assert robot._handlers["unsubscribe_event"] == [(unsubscribe_handler, 0)] @robot.voice def voice_handler(): pass assert robot._handlers["voice"] == [(voice_handler, 0)] @robot.click def click_handler(): pass assert robot._handlers["click_event"] == [(click_handler, 0)] @robot.key_click("MENU") def menu_handler(): pass assert len(robot._handlers["click_event"]) == 2 @robot.scan def scan_handler(): pass assert robot._handlers["scan_event"] == [(scan_handler, 0)] @robot.scancode_push def scancode_push_handler(): pass assert robot._handlers["scancode_push_event"] == [(scancode_push_handler, 0)] @robot.scancode_waitmsg def scancode_waitmsg_handler(): pass assert robot._handlers["scancode_waitmsg_event"] == [ (scancode_waitmsg_handler, 0) ]
def test_register_handlers(): robot = WeRoBot(enable_session=False) for type in robot.message_types: assert hasattr(robot, type) or \ hasattr(robot, type.replace('_event', '')) @robot.text def text_handler(): return "Hi" assert robot._handlers["text"] == [(text_handler, 0)] @robot.image def image_handler(message): return 'nice pic' assert robot._handlers["image"] == [(image_handler, 1)] assert robot.get_handlers("text") == [(text_handler, 0)] @robot.handler def handler(message, session): pass assert robot.get_handlers("text") == [(text_handler, 0), (handler, 2)] @robot.location def location_handler(): pass assert robot._handlers["location"] == [(location_handler, 0)] @robot.link def link_handler(): pass assert robot._handlers["link"] == [(link_handler, 0)] @robot.subscribe def subscribe_handler(): pass assert robot._handlers["subscribe_event"] == [(subscribe_handler, 0)] @robot.unsubscribe def unsubscribe_handler(): pass assert robot._handlers["unsubscribe_event"] == [(unsubscribe_handler, 0)] @robot.voice def voice_handler(): pass assert robot._handlers["voice"] == [(voice_handler, 0)] @robot.click def click_handler(): pass assert robot._handlers["click_event"] == [(click_handler, 0)] @robot.key_click("MENU") def menu_handler(): pass assert len(robot._handlers["click_event"]) == 2
def test_register_handlers(): # noqa: C901 robot = WeRoBot(SESSION_STORAGE=False) for type in robot.message_types: assert hasattr(robot, type) or hasattr(robot, type.replace('_event', '')) @robot.text def text_handler(): return "Hi" assert robot._handlers["text"] == [(text_handler, 0)] @robot.image def image_handler(message): return 'nice pic' assert robot._handlers["image"] == [(image_handler, 1)] assert robot.get_handlers("text") == [(text_handler, 0)] @robot.handler def handler(message, session): pass assert robot.get_handlers("text") == [(text_handler, 0), (handler, 2)] @robot.video def video_handler(): pass assert robot._handlers["video"] == [(video_handler, 0)] assert robot.get_handlers("video") == [(video_handler, 0), (handler, 2)] @robot.shortvideo def shortvideo_handler(): pass assert robot._handlers["shortvideo"] == [(shortvideo_handler, 0)] assert robot.get_handlers("shortvideo") == [ (shortvideo_handler, 0), (handler, 2) ] @robot.location def location_handler(): pass assert robot._handlers["location"] == [(location_handler, 0)] @robot.link def link_handler(): pass assert robot._handlers["link"] == [(link_handler, 0)] @robot.subscribe def subscribe_handler(): pass assert robot._handlers["subscribe_event"] == [(subscribe_handler, 0)] @robot.unsubscribe def unsubscribe_handler(): pass assert robot._handlers["unsubscribe_event"] == [(unsubscribe_handler, 0)] @robot.voice def voice_handler(): pass assert robot._handlers["voice"] == [(voice_handler, 0)] @robot.click def click_handler(): pass assert robot._handlers["click_event"] == [(click_handler, 0)] @robot.key_click("MENU") def menu_handler(): pass assert len(robot._handlers["click_event"]) == 2 @robot.scan def scan_handler(): pass assert robot._handlers["scan_event"] == [(scan_handler, 0)] @robot.scancode_push def scancode_push_handler(): pass assert robot._handlers["scancode_push_event"] == [ (scancode_push_handler, 0) ] @robot.scancode_waitmsg def scancode_waitmsg_handler(): pass assert robot._handlers["scancode_waitmsg_event"] == [ (scancode_waitmsg_handler, 0) ]