Skip to content
Snippets Groups Projects
Commit 8a410ff5 authored by jkerdreu's avatar jkerdreu
Browse files

Initial release



git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2794 b32b6428-25c9-4566-ad07-03861ab6144f
parent 82c15af3
Branches
No related tags found
No related merge requests found
import unittest
from xaal.lib import Engine,Device,MessageFactory,MessageType
from xaal.lib import engine,tools
from xaal.lib.messages import Message
TEST_PORT=6666
def new_engine():
engine = Engine(port=TEST_PORT)
return engine
class TestEngine(unittest.TestCase):
def test_run_action(self):
target = Device("test.basic",tools.get_random_uuid())
def action_1():
return "action_1"
def action_2(_value=None):
return "action_%s" % _value
def action_3():
raise Exception
target.add_method("action_1",action_1)
target.add_method("action_2",action_2)
target.add_method("action_3",action_3)
msg = Message()
msg.msg_type = MessageType.REQUEST
msg.targets = [target.address]
# simple test method
msg.action = 'action_1'
result = engine.run_action(msg,target)
self.assertEqual(result,"action_1")
# test with value
msg.action = 'action_2'
msg.body = {'value':'2'}
result = engine.run_action(msg,target)
self.assertEqual(result,"action_2")
# Exception in method
msg.action = 'action_3'
with self.assertRaises(engine.XAALError):
result = engine.run_action(msg,target)
# unknown method
msg.action = 'missing'
with self.assertRaises(engine.XAALError):
result = engine.run_action(msg,target)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment