summaryrefslogtreecommitdiff
path: root/src/leap/common/events/test_events.py
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-06-28 14:55:33 -0300
committerTomás Touceda <chiiph@leap.se>2013-06-28 14:55:33 -0300
commitd071efe20a285e579111f568e2ff994a6171249f (patch)
tree824ea959c02c8ed3af36c0cec8421e0748d311cc /src/leap/common/events/test_events.py
parentb966eec96fd3621908baab8697de8e2ed61ba136 (diff)
parenta0f78f9d708cc6fe686ee5860cdc34909391b14b (diff)
Merge branch 'release-0.2.5'
Diffstat (limited to 'src/leap/common/events/test_events.py')
-rw-r--r--src/leap/common/events/test_events.py88
1 files changed, 0 insertions, 88 deletions
diff --git a/src/leap/common/events/test_events.py b/src/leap/common/events/test_events.py
deleted file mode 100644
index ae55319..0000000
--- a/src/leap/common/events/test_events.py
+++ /dev/null
@@ -1,88 +0,0 @@
-import unittest
-from protobuf.socketrpc import RpcService
-from leap.common import events
-from leap.common.events import service
-from leap.common.events.signal_pb2 import (
- SignalRequest,
- SignalService,
- SignalService_Stub,
-)
-
-
-port = 8090
-
-class EventsTestCase(unittest.TestCase):
-
- def _start_service(self):
- return service.SignalServiceThread.start_service(port)
-
- def setUp(self):
- super(EventsTestCase, self).setUp()
- self._service = self._start_service()
-
- def tearDown(self):
- events.registered_callbacks = {}
- super(EventsTestCase, self).tearDown()
-
- def test_service_singleton(self):
- self.assertTrue(self._service.get_instance() == self._service,
- "Can't get singleton class for service.")
-
- def test_register_signal(self):
- key = SignalRequest.SOLEDAD_CREATING_KEYS
- self.assertEqual({}, events.registered_callbacks,
- 'There should be no registered_callbacks events when '
- 'service has just started.')
- events.register(key, lambda x: True)
- self.assertEqual(1, len(events.registered_callbacks),
- 'Wrong number of registered callbacks.')
- self.assertEqual(events.registered_callbacks.keys(), [key],
- 'Couldn\'t locate registered signal.')
- events.register(key, lambda x: True)
- self.assertEqual(1, len(events.registered_callbacks),
- 'Wrong number of registered callbacks.')
- self.assertEqual(events.registered_callbacks.keys(), [key],
- 'Couldn\'t locate registered signal.')
- self.assertEqual(
- 2,
- len(events.registered_callbacks[SignalRequest.SOLEDAD_CREATING_KEYS]),
- 'Wrong number of registered callbacks.')
- key2 = SignalRequest.CLIENT_UID
- events.register(key2, lambda x: True)
- self.assertEqual(2, len(events.registered_callbacks),
- 'Wrong number of registered callbacks.')
- self.assertEqual(
- sorted(events.registered_callbacks.keys()),
- sorted([key2, key]),
- 'Wrong keys in `registered_keys`.')
-
- def test_register_signal_replace(self):
- key = SignalRequest.SOLEDAD_CREATING_KEYS
- cbk = lambda x: True
- self.assertEqual({}, events.registered_callbacks,
- 'There should be no registered_callbacks events when '
- 'service has just started.')
- events.register(key, cbk, uid=1)
- self.assertRaises(Exception, events.register, key, lambda x: True, uid=1)
- self.assertEquals(1,
- events.register(key, lambda x: True, uid=1, replace=True),
- "Could not replace callback.")
- self.assertEqual(1, len(events.registered_callbacks),
- 'Wrong number of registered callbacks.')
- self.assertEqual(events.registered_callbacks.keys(), [key],
- 'Couldn\'t locate registered signal.')
-
- def test_signal_response_status(self):
- sig = SignalRequest.SOLEDAD_CREATING_KEYS
- cbk = lambda x: True
- events.register(sig, cbk)
- request = SignalRequest()
- request.id = 1
- request.signal = sig
- request.content = 'my signal contents'
- request.mac_method = 'nomac'
- request.mac = ""
- service = RpcService(SignalService_Stub, port, 'localhost')
- response = service.signal(request, timeout=1000)
- self.assertEqual(response.OK, response.status,
- 'Wrong response status.')