1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-12 19:27:17 +00:00

Add LinearFSM example to test project

This commit is contained in:
Kristóf Tóth 2018-04-10 11:19:53 +02:00
parent 8519479ebd
commit 7331858055
3 changed files with 30 additions and 28 deletions

View File

@ -1,26 +0,0 @@
from tfw.fsm_base import FSMBase
class SQLInjectionFSM(FSMBase):
states = [
'start',
'stripped_code',
'sql',
'commented_code',
'sql_with_substitutions',
'sql_output',
'end',
]
transitions = [
{'trigger': 'webide', 'source': '*', 'dest': 'stripped_code'}, # TODO: delet this
{'trigger': 'webide', 'source': 'start', 'dest': 'stripped_code'},
{'trigger': 'login', 'source': 'stripped_code', 'dest': 'sql'},
{'trigger': 'logger', 'source': 'sql', 'dest': 'commented_code'},
{'trigger': 'webide', 'source': 'commented_code', 'dest': 'sql_with_substitutions'},
{'trigger': 'logger', 'source': 'sql_with_substitutions', 'dest': 'sql_output'},
{'trigger': 'logger', 'source': 'sql_output', 'dest': 'end'},
{'trigger': 'reset', 'source': 'end', 'dest': 'start'},
]
def __init__(self):
super().__init__('start')

26
solvable/src/test_fsm.py Normal file
View File

@ -0,0 +1,26 @@
from tfw import LinearFSM
from tfw.networking import MessageSender
class TestFSM(LinearFSM):
def __init__(self, number_of_steps):
super().__init__(number_of_steps)
self.message_sender = MessageSender()
def on_enter_1(self, event_data):
self.state_notify(1)
def on_enter_2(self, event_data):
self.state_notify(2)
def on_enter_3(self, event_data):
self.state_notify(3)
def on_enter_4(self, event_data):
self.state_notify(4)
def on_enter_5(self, event_data):
self.state_notify(5)
def state_notify(self, state):
self.message_sender.send('TestFSM', 'Entered state {}!'.format(state))

View File

@ -1,9 +1,11 @@
import sys
from functools import partial
import zmq
import tornado
from tornado.ioloop import IOLoop
from sql_injection_fsm import SQLInjectionFSM
from test_fsm import TestFSM
from tfw.networking import TFWServer
from tfw.config import TFWENV
from tfw.config.logs import logging
@ -12,7 +14,7 @@ LOG = logging.getLogger(__name__)
if __name__ == '__main__':
TFWServer(SQLInjectionFSM).listen(TFWENV.WEB_PORT)
TFWServer(partial(TestFSM, 5)).listen(TFWENV.WEB_PORT)
LOG.debug('Python version: %s', sys.version[:5])
LOG.debug('Tornado version: %s', tornado.version)
LOG.debug('ZeroMQ version: %s', zmq.zmq_version())