def test_action_event_from_subscribed_action(self): event_a = generate_composite_event(NAME_A) prod = ActionProducer(NoAction(bool_return=True)) # sub subscribes to prod sub = StubProducerSubscriber() prod.subscribe(NAME_A, sub) # action subscribes to prod action = NoAction(bool_return=True) action.subscribe(prod) action.execute(event_a) self.assertEqual(1, len(sub.action)) self.assertIsInstance(sub.action[0], ActionEvent) self.assertEqual(event_a, sub.action[0].for_event)
def test_action_subscribe_unsubscribe(self): action = NoAction(bool_return=True) actionsub = StubBoboActionSubscriber() # subscribe action.subscribe(actionsub) c_event_a = generate_composite_event(NAME_A) action.execute(c_event_a) # event should cause ActionEvent to be passed to sub self.assertEqual(1, len(actionsub.events)) self.assertIsInstance(actionsub.events[0], ActionEvent) self.assertEqual(c_event_a, actionsub.events[0].for_event) # unsubscribe action.unsubscribe(actionsub) action.execute(generate_composite_event(NAME_B)) # no new ActionEvent self.assertEqual(1, len(actionsub.events))