def test_additonal_controllers(self): """ """ core_controller = GACoreController( garuda_uuid='test-garuda', redis_info={ 'host': '127.0.0.1', 'port': 6379, 'db': 6 }, authentication_plugins=[FakeAuthPlugin()]) with self.assertRaises(KeyError): core_controller.additional_controller(identifier='nope') core_controller = GACoreController( garuda_uuid='test-garuda', redis_info={ 'host': '127.0.0.1', 'port': 6379, 'db': 6 }, additional_controller_classes=[AdditionalController], authentication_plugins=[FakeAuthPlugin()]) self.assertIsNotNone( core_controller.additional_controller( identifier='test.controller.additional'))
def test_additonal_controllers(self): """ """ core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, authentication_plugins=[FakeAuthPlugin()]) with self.assertRaises(KeyError): core_controller.additional_controller(identifier='nope') core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[AdditionalController], authentication_plugins=[FakeAuthPlugin()]) self.assertIsNotNone(core_controller.additional_controller(identifier='test.controller.additional'))
def test_unsubscribe_all_online(self): """ """ core_controller = GACoreController( garuda_uuid='test-garuda', redis_info={ 'host': '127.0.0.1', 'port': 6379, 'db': 6 }, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') def handler(data): self.assertEquals(data, 'hello') controller.start_listening_to_events() controller.subscribe('test-channel1', handler) controller.subscribe('test-channel2', handler) self.assertTrue('test-channel1' in controller.subscriptions) self.assertTrue('test-channel2' in controller.subscriptions) controller.unsubscribe_all() controller.stop_listening_to_events() self.assertFalse('test-channel1' in controller.subscriptions) self.assertFalse('test-channel2' in controller.subscriptions)
def test_lifecycle(self): """ """ core_controller = GACoreController( garuda_uuid='test-garuda', redis_info={ 'host': '127.0.0.1', 'port': 6379, 'db': 6 }, additional_controller_classes=[AdditionalController], authentication_plugins=[FakeAuthPlugin()]) additional = core_controller.additional_controller( 'test.controller.additional') self.assertTrue(additional.is_ready) core_controller.start() self.assertTrue(core_controller.running) self.assertTrue(additional.is_started) with self.assertRaises(RuntimeError): core_controller.start() core_controller.stop() self.assertFalse(core_controller.running) self.assertFalse(additional.is_started) with self.assertRaises(RuntimeError): core_controller.stop()
def test_offline_subscriptions(self): """ """ core_controller = GACoreController( garuda_uuid='test-garuda', redis_info={ 'host': '127.0.0.1', 'port': 6379, 'db': 6 }, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') def handler(data): pass controller.subscribe('test-channel1', handler) controller.subscribe('test-channel2', handler) self.assertEquals(controller.subscriptions['test-channel1'], handler) self.assertEquals(controller.subscriptions['test-channel2'], handler) self.assertTrue('test-channel1' in controller.subscriptions) self.assertTrue('test-channel2' in controller.subscriptions) controller.unsubscribe('test-channel1') controller.unsubscribe('test-channel2') self.assertEquals(len(controller.subscriptions), 0) self.assertFalse('test-channel1' in controller.subscriptions) self.assertFalse('test-channel2' in controller.subscriptions)
def test_stop_listening_to_events_when_not_listening(self): """ """ core_controller = GACoreController( garuda_uuid='test-garuda', redis_info={ 'host': '127.0.0.1', 'port': 6379, 'db': 6 }, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') controller.stop_listening_to_events()
def test_start_stop_twice(self): """ """ core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') controller.start_listening_to_events() thread = controller._pubsub_thread controller.start_listening_to_events() self.assertEquals(controller._pubsub_thread, thread) controller.stop_listening_to_events() controller.stop_listening_to_events() self.assertIsNone(controller._pubsub_thread)
def test_publish(self): """ """ core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') def handler(data): self.assertEquals(data, 'hello') core_controller.start() controller.subscribe('test-channel', handler) controller.start_listening_to_events() controller.publish('test-channel', 'hello') controller.stop_listening_to_events() core_controller.stop()
def test_lifecycle(self): """ """ core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') self.assertIsNotNone(controller) self.assertFalse(controller.is_started) self.assertTrue(controller.is_ready) core_controller.start() self.assertTrue(controller.is_started) self.assertTrue(controller.is_ready) core_controller.stop() self.assertFalse(controller.is_started) self.assertTrue(controller.is_ready)
def test_unsubscribe_all_online(self): """ """ core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') def handler(data): self.assertEquals(data, 'hello') controller.start_listening_to_events() controller.subscribe('test-channel1', handler) controller.subscribe('test-channel2', handler) self.assertTrue('test-channel1' in controller.subscriptions) self.assertTrue('test-channel2' in controller.subscriptions) controller.unsubscribe_all() controller.stop_listening_to_events() self.assertFalse('test-channel1' in controller.subscriptions) self.assertFalse('test-channel2' in controller.subscriptions)
def test_publish(self): """ """ core_controller = GACoreController( garuda_uuid='test-garuda', redis_info={ 'host': '127.0.0.1', 'port': 6379, 'db': 6 }, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') def handler(data): self.assertEquals(data, 'hello') core_controller.start() controller.subscribe('test-channel', handler) controller.start_listening_to_events() controller.publish('test-channel', 'hello') controller.stop_listening_to_events() core_controller.stop()
def test_start_stop_twice(self): """ """ core_controller = GACoreController( garuda_uuid='test-garuda', redis_info={ 'host': '127.0.0.1', 'port': 6379, 'db': 6 }, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') controller.start_listening_to_events() thread = controller._pubsub_thread controller.start_listening_to_events() self.assertEquals(controller._pubsub_thread, thread) controller.stop_listening_to_events() controller.stop_listening_to_events() self.assertIsNone(controller._pubsub_thread)
def test_lifecycle(self): """ """ core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[AdditionalController], authentication_plugins=[FakeAuthPlugin()]) additional = core_controller.additional_controller('test.controller.additional') self.assertTrue(additional.is_ready) core_controller.start() self.assertTrue(core_controller.running) self.assertTrue(additional.is_started) with self.assertRaises(RuntimeError): core_controller.start() core_controller.stop() self.assertFalse(core_controller.running) self.assertFalse(additional.is_started) with self.assertRaises(RuntimeError): core_controller.stop()
def test_lifecycle(self): """ """ core_controller = GACoreController( garuda_uuid='test-garuda', redis_info={ 'host': '127.0.0.1', 'port': 6379, 'db': 6 }, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') self.assertIsNotNone(controller) self.assertFalse(controller.is_started) self.assertTrue(controller.is_ready) core_controller.start() self.assertTrue(controller.is_started) self.assertTrue(controller.is_ready) core_controller.stop() self.assertFalse(controller.is_started) self.assertTrue(controller.is_ready)
def test_offline_subscriptions(self): """ """ core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') def handler(data): pass controller.subscribe('test-channel1', handler) controller.subscribe('test-channel2', handler) self.assertEquals(controller.subscriptions['test-channel1'], handler) self.assertEquals(controller.subscriptions['test-channel2'], handler) self.assertTrue('test-channel1' in controller.subscriptions) self.assertTrue('test-channel2' in controller.subscriptions) controller.unsubscribe('test-channel1') controller.unsubscribe('test-channel2') self.assertEquals(len(controller.subscriptions), 0) self.assertFalse('test-channel1' in controller.subscriptions) self.assertFalse('test-channel2' in controller.subscriptions)
def test_stop_listening_to_events_when_not_listening(self): """ """ core_controller = GACoreController(garuda_uuid='test-garuda', redis_info={'host': '127.0.0.1', 'port': 6379, 'db': 6}, additional_controller_classes=[FakeController]) controller = core_controller.additional_controller(identifier='the.id') controller.stop_listening_to_events()