def testRaisesOnDeletingMultipleNotifications(self): # Check that there are three pending notifications and no shown ones yet. (pending, shown) = self._GetNotifications() self.assertEqual(len(pending), 3) self.assertEqual(len(shown), 0) # Delete all pending notifications on TIME_0. args = user_plugin.ApiDeletePendingUserNotificationArgs( timestamp=self.TIME_0) with self.assertRaises(aff4_users.UniqueKeyError): self.handler.Handle(args, token=self.token) # Check that the notifications were not changed in the process. (pending, shown) = self._GetNotifications() self.assertEqual(len(pending), 3) self.assertEqual(len(shown), 0)
def testUnknownTimestampIsIgnored(self): # Check that there are three pending notifications and no shown ones yet. (pending, shown) = self._GetNotifications() self.assertEqual(len(pending), 3) self.assertEqual(len(shown), 0) # A timestamp not matching any pending notifications does not change any of # the collections. args = user_plugin.ApiDeletePendingUserNotificationArgs( timestamp=self.TIME_2) self.handler.Handle(args, token=self.token) # We should still have the same number of pending and shown notifications. (pending, shown) = self._GetNotifications() self.assertEqual(len(pending), 3) self.assertEqual(len(shown), 0)
def testDeletesFromPendingAndAddsToShown(self): # Check that there are three pending notifications and no shown ones yet. (pending, shown) = self._GetNotifications() self.assertEqual(len(pending), 3) self.assertEqual(len(shown), 0) # Delete a pending notification. args = user_plugin.ApiDeletePendingUserNotificationArgs( timestamp=self.TIME_1) self.handler.Handle(args, token=self.token) # After the deletion, two notifications should be pending and one shown. (pending, shown) = self._GetNotifications() self.assertEqual(len(pending), 2) self.assertEqual(len(shown), 1) self.assertTrue("<some other message>" in shown[0].message) self.assertEqual(shown[0].timestamp, self.TIME_1)