def test_unsubscribe_non_existant_without_error(self):
        """Test that unsubscribing from a notification that isn't being listened to, and from a controller that hasn't
        been subscribed to, doesn't raise an error."""
        v = ViewState(MagicMock())
        n = NotificationCentre(v)

        n.unsubscribe_from_notification('non-existant', 'not.a.real.path')
        n.subscribe_to_notification('real-notification', 'listener.path', 'a.real.path')
        n.unsubscribe_from_notification('real-notification', 'listener.path', 'not.a.real.path')
Esempio n. 2
0
    def test_notification_unsubscribe(self):
        """After a component unsubscribes, it should not receive that notification any more (but should still receive
        others that it is subscribed to)."""
        v = ViewState(MagicMock())
        n = NotificationCentre(v)
        component = MagicMock()
        v.component_from_path = MagicMock(return_value=component)

        n.subscribe_to_notification('test_notification', 'page.test_component')
        n.subscribe_to_notification('test_notification2', 'page.test_component')
        n.unsubscribe_from_notification('test_notification', 'page.test_component')
        n.post_notification('test_notification')
        self.assertEqual(component.process_notification.call_count, 0)
        n.post_notification('test_notification2')
        component.process_notification.assert_called_with('test_notification2', None)