Add cenerator to enable testing

This commit is contained in:
Bálint Bokros 2018-02-02 16:49:48 +01:00
parent 2530fe43ea
commit dbc2d1c0ea

View File

@ -1,7 +1,18 @@
from itertools import cycle
from tfw.networking.serialization import deserialize_all
from tfw.networking.event_handlers.server_connector import ServerConnector
def cenator():
yield from [
'**Your time is up**',
'`My time is now`',
'_You can\'t see me_',
'My time is now'
]
class EventHandlerBase:
def __init__(self, anchor):
self.server_connector = ServerConnector()
@ -10,9 +21,13 @@ class EventHandlerBase:
self.subscribe(self.anchor)
self.subscribe('reset')
self.server_connector.register_callback(self.event_handler_callback)
self.cenerator = cycle(cenator())
def event_handler_callback(self, msg_parts):
anchor, message = deserialize_all(*msg_parts)
from .message_sender import MessageSender
ms = MessageSender()
ms.send('JOHN CENA', next(self.cenerator))
response = self.handle_event(anchor, message) if anchor != 'reset' else self.handle_reset(message)
if response is None: return
self.server_connector.send(anchor, response)