def testClosingOneNotificationLeavesAnotherIntact(self): with self.ACLChecksDisabled(): with aff4.FACTORY.Create( aff4.GlobalNotificationStorage.DEFAULT_PATH, aff4_type="GlobalNotificationStorage", mode="rw", token=self.token) as storage: storage.AddNotification( rdfvalue.GlobalNotification( type=rdfvalue.GlobalNotification.Type.ERROR, header="Oh no, we're doomed!", content="Houston, Houston, we have a prob...", link="http://www.google.com")) storage.AddNotification( rdfvalue.GlobalNotification( type=rdfvalue.GlobalNotification.Type.INFO, header="Nothing to worry about!", link="http://www.google.com")) self.Open("/") self.WaitUntil(self.IsTextPresent, "Houston, Houston, we have a prob...") self.Click("css=#global-notification .alert-error button.close") self.WaitUntilNot(self.IsTextPresent, "Houston, Houston, we have a prob...") self.WaitUntil(self.IsTextPresent, "Nothing to worry about!") self.Open("/") self.WaitUntil(self.IsTextPresent, "Nothing to worry about!") self.assertFalse( self.IsTextPresent("Houston, Houston, we have a prob..."))
def testNewNotificationReplacesPreviousNotificationOfTheSameType(self): with self.ACLChecksDisabled(): with aff4.FACTORY.Create( aff4.GlobalNotificationStorage.DEFAULT_PATH, aff4_type="GlobalNotificationStorage", mode="rw", token=self.token) as storage: storage.AddNotification( rdfvalue.GlobalNotification( type=rdfvalue.GlobalNotification.Type.ERROR, header="Oh no, we're doomed!", content="Houston, Houston, we have a prob...", link="http://www.google.com")) self.Open("/") self.WaitUntil(self.IsTextPresent, "Houston, Houston, we have a prob...") with self.ACLChecksDisabled(): with aff4.FACTORY.Create( aff4.GlobalNotificationStorage.DEFAULT_PATH, aff4_type="GlobalNotificationStorage", mode="rw", token=self.token) as storage: storage.AddNotification( rdfvalue.GlobalNotification( type=rdfvalue.GlobalNotification.Type.ERROR, content="Too late to do anything!", link="http://www.google.com")) self.Open("/") self.WaitUntil(self.IsTextPresent, "Too late to do anything!") self.assertFalse( self.IsTextPresent("Houston, Houston, we have a prob..."))
def testGlobalNotificationDisappearsAfterClosing(self): with self.ACLChecksDisabled(): with aff4.FACTORY.Create( aff4.GlobalNotificationStorage.DEFAULT_PATH, aff4_type="GlobalNotificationStorage", mode="rw", token=self.token) as storage: storage.AddNotification( rdfvalue.GlobalNotification( type=rdfvalue.GlobalNotification.Type.ERROR, header="Oh no, we're doomed!", content="Houston, Houston, we have a prob...", link="http://www.google.com")) self.Open("/") self.WaitUntil(self.IsTextPresent, "Houston, Houston, we have a prob...") self.Click("css=#global-notification button.close") self.WaitUntilNot(self.IsTextPresent, "Houston, Houston, we have a prob...") self.Open("/") self.WaitUntil(self.IsElementPresent, "client_query") self.WaitUntilNot(self.IsTextPresent, "Houston, Houston, we have a prob...")
def testNotificationIsReturnedWhenItIsSet(self): with aff4.FACTORY.Create(aff4.GlobalNotificationStorage.DEFAULT_PATH, aff4_type="GlobalNotificationStorage", mode="rw", token=self.token) as storage: storage.AddNotification(rdfvalue.GlobalNotification( type=rdfvalue.GlobalNotification.Type.ERROR, header="foo", content="bar", link="http://www.google.com")) notifications = self.user.GetPendingGlobalNotifications() self.assertTrue(notifications) self.assertEqual(len(notifications), 1) self.assertEqual(notifications[0].header, "foo") self.assertEqual(notifications[0].content, "bar")
def testNotificationsOfDifferentTypesAreShownTogether(self): with self.ACLChecksDisabled(): with aff4.FACTORY.Create( aff4.GlobalNotificationStorage.DEFAULT_PATH, aff4_type="GlobalNotificationStorage", mode="rw", token=self.token) as storage: storage.AddNotification( rdfvalue.GlobalNotification( type=rdfvalue.GlobalNotification.Type.ERROR, header="Oh no, we're doomed!", content="Houston, Houston, we have a prob...", link="http://www.google.com")) storage.AddNotification( rdfvalue.GlobalNotification( type=rdfvalue.GlobalNotification.Type.INFO, header="Nothing to worry about!", link="http://www.google.com")) self.Open("/") self.WaitUntil(self.IsTextPresent, "Houston, Houston, we have a prob...") self.WaitUntil(self.IsTextPresent, "Nothing to worry about!")
def testNotificationIsNotReturnedWhenItExpires(self): with test_lib.FakeTime(100): with aff4.FACTORY.Create(aff4.GlobalNotificationStorage.DEFAULT_PATH, aff4_type="GlobalNotificationStorage", mode="rw", token=self.token) as storage: storage.AddNotification(rdfvalue.GlobalNotification( type=rdfvalue.GlobalNotification.Type.ERROR, header="foo", content="bar", duration=rdfvalue.Duration("1h"),)) with test_lib.FakeTime(101): notifications = self.user.GetPendingGlobalNotifications() self.assertTrue(notifications) with test_lib.FakeTime(100 + 3600 + 1): notifications = self.user.GetPendingGlobalNotifications() self.assertFalse(notifications)