Exemple #1
0
 def test_fanout_multiple_observers(self):
     """
     More observers can be added to the Fanout observer, which successfully
     sends all new events to all the sub-observers in its list.
     """
     messages = [{str(i): 'message'} for i in range(3)]
     obs1, obs2 = [], []
     fanout = FanoutObserver(obs1.append)
     fanout(messages[0].copy())
     fanout.add_observer(obs2.append)
     fanout(messages[1].copy())
     fanout(messages[2].copy())
     self.assertEqual(obs1, messages)
     self.assertEqual(obs2, messages[1:])
Exemple #2
0
 def test_fanout_multiple_observers(self):
     """
     More observers can be added to the Fanout observer, which successfully
     sends all new events to all the sub-observers in its list.
     """
     messages = [{str(i): 'message'} for i in range(3)]
     obs1, obs2 = [], []
     fanout = FanoutObserver(obs1.append)
     fanout(messages[0].copy())
     fanout.add_observer(obs2.append)
     fanout(messages[1].copy())
     fanout(messages[2].copy())
     self.assertEqual(obs1, messages)
     self.assertEqual(obs2, messages[1:])
Exemple #3
0
    def test_subobservers_do_not_affect_each_other(self):
        """
        A subobserver that mutates events will not affect other subobservers.
        """
        obs, obs_mutated = [], []

        def mutate(event):
            event.pop('delete_me', None)
            event['added'] = 'added'
            obs_mutated.append(event)

        fanout = FanoutObserver(obs.append)
        fanout.add_observer(mutate)
        fanout({'only': 'message', 'delete_me': 'go'})

        self.assertEqual(obs, [{'only': 'message', 'delete_me': 'go'}])
        self.assertEqual(obs_mutated, [{'only': 'message', 'added': 'added'}])
Exemple #4
0
    def test_subobservers_do_not_affect_each_other(self):
        """
        A subobserver that mutates events will not affect other subobservers.
        """
        obs, obs_mutated = [], []

        def mutate(event):
            event.pop('delete_me', None)
            event['added'] = 'added'
            obs_mutated.append(event)

        fanout = FanoutObserver(obs.append)
        fanout.add_observer(mutate)
        fanout({'only': 'message', 'delete_me': 'go'})

        self.assertEqual(obs, [{'only': 'message', 'delete_me': 'go'}])
        self.assertEqual(obs_mutated, [{'only': 'message', 'added': 'added'}])
Exemple #5
0
 def test_fanout_single_observer(self):
     """
     Fanout observer successfully sends all events if it only has a single
     subobserver.
     """
     messages = [{str(i): 'message'} for i in range(3)]
     obs = []
     fanout = FanoutObserver(obs.append)
     for mess in messages:
         fanout(mess.copy())
     self.assertEqual(obs, messages)