49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
__author__ = 'RemiZOffAlex'
|
|
__email__ = 'remizoffalex@mail.ru'
|
|
|
|
import unittest
|
|
|
|
from router.dispatcher import Dispatcher
|
|
|
|
|
|
def comparator1(params):
|
|
return 'param1' in params
|
|
|
|
|
|
def comparator2(params):
|
|
return params['param2']=='value2'
|
|
|
|
def action(params):
|
|
return params['param3']
|
|
|
|
|
|
class TestDispatcher(unittest.TestCase):
|
|
def test_dispatcher(self):
|
|
dispatcher = Dispatcher()
|
|
params = {
|
|
'param1': 'value1',
|
|
'param2': 'value2',
|
|
'param3': 'value3'
|
|
}
|
|
dispatcher.register('name', comparator1, action)
|
|
method = dispatcher(params)
|
|
result = method(params)
|
|
self.assertEqual(result, 'value3')
|
|
|
|
def test_sub(self):
|
|
dispatcher = Dispatcher()
|
|
params ={
|
|
'param1': 'value1',
|
|
'param2': 'value2',
|
|
'param3': 'value3'
|
|
}
|
|
|
|
sub = Dispatcher()
|
|
sub.register('name', comparator2, action)
|
|
|
|
dispatcher.register('name', comparator1, sub)
|
|
method = dispatcher(params)
|
|
result = method(params)
|
|
sub_result = result(params)
|
|
self.assertEqual(sub_result, 'value3')
|