def test_areNotificationsDisabled_all_off(self): center = NotificationCenter() observable1 = _TestObservable(center, "Observable1") observable2 = _TestObservable(center, "Observable2") observer = NotificationTestObserver() center.addObserver(observer, "notificationCallback", "A", observable1) center.addObserver(observer, "notificationCallback", "B", observable2) center.disableNotifications() self.assertTrue(center.areNotificationsDisabled()) center.enableNotifications() self.assertFalse(center.areNotificationsDisabled())
def test_areNotificationsDisabled_observer_off(self): center = NotificationCenter() observable1 = _TestObservable(center, "Observable1") observer1 = NotificationTestObserver() observer2 = NotificationTestObserver() center.addObserver(observer1, "notificationCallback", "A", observable1) center.addObserver(observer2, "notificationCallback", "A", observable1) center.disableNotifications(observer=observer1) self.assertTrue(center.areNotificationsDisabled(observer=observer1)) self.assertFalse(center.areNotificationsDisabled(observer=observer2)) center.enableNotifications(observer=observer1) self.assertFalse(center.areNotificationsDisabled(observer=observer1))
def test_disable_enableNotifications_specific_observer(self): # disable all notifications for a specific observer center = NotificationCenter() observable1 = _TestObservable(center, "Observable1") observable2 = _TestObservable(center, "Observable2") observer = NotificationTestObserver() center.addObserver(observer, "notificationCallback", "A", observable1) center.addObserver(observer, "notificationCallback", "B", observable1) center.addObserver(observer, "notificationCallback", "C", observable2) center.disableNotifications(observer=observer) observable1.postNotification("A") observable1.postNotification("B") observable2.postNotification("C") center.enableNotifications(observer=observer) observable1.postNotification("A") self.assertEqual(observer.stack[-1], ("A", "Observable1"))