def test_force_same_notification_multiple_queue(self): """The same notification will be queued twice if the force arg is True.""" v = ViewState(MagicMock()) n = NotificationCentre(v) n.queue_client_notification('test_name', 'page.test_component') n.queue_client_notification('test_name', 'page.test_component', force=True) queued_notifications = [notification for notification in n] self.assertEqual(len(queued_notifications), 2) self.assertEqual(queued_notifications[0], queued_notifications[1])
def test_client_notification_queue_and_retrieve(self): """Client notifications are queued and retrieved in FIFO order.""" v = ViewState(MagicMock()) n = NotificationCentre(v) n.queue_client_notification('test_name', 'page.test_component') n.queue_client_notification('test_name2', 'page.test_component2', 'somedata') # notifications are retrieved FIFO queued_notifications = [notification for notification in n] self.assertEqual(len(queued_notifications), 2) self.assertEqual({'name': 'test_name', 'path': 'page.test_component'}, queued_notifications[0]) self.assertEqual({'name': 'test_name2', 'path': 'page.test_component2', 'data': 'somedata'}, queued_notifications[1]) # queue should now be empty self.assertEqual(len([notification for notification in n]), 0)
def test_queue_load_shortcut_with_scroll_top(self): """Test that the queue_load shortcut queues a client load:scrolltop notification for the specified path.""" v = ViewState(MagicMock()) nc = NotificationCentre(v) nc.queue_client_notification = MagicMock() nc.queue_load('test.controller', scroll_top=True) nc.queue_client_notification.assert_called_with('load:scroll_top', 'test.controller')
def test_same_notification_multiple_queue(self): """The same notification will not be queued twice, however if any of name, path or data differs, it will.""" v = ViewState(MagicMock()) n = NotificationCentre(v) n.queue_client_notification('test_name', 'page.test_component') n.queue_client_notification('test_name', 'page.test_component') self.assertEqual(len([notification for notification in n]), 1) n.queue_client_notification('test_name', 'page.test_component') n.queue_client_notification('test_name', 'page.test_component', 'somedata') self.assertEqual(len([notification for notification in n]), 2) n.queue_client_notification('test_name', 'page.test_component2') n.queue_client_notification('test_name', 'page.test_component') self.assertEqual(len([notification for notification in n]), 2) n.queue_client_notification('test_name', 'page.test_component') n.queue_client_notification('test_name2', 'page.test_component') self.assertEqual(len([notification for notification in n]), 2)