<s> """<STR_LIT>""" <EOL> from grr . gui import runtests_test <EOL> from grr . gui . api_plugins . client import ApiSearchClientsHandler <EOL> from grr . lib import access_control <EOL> from grr . lib import aff4 <EOL> from grr . lib import flags <EOL> from grr . lib import flow <EOL> from grr . lib import test_lib <EOL> from grr . lib import utils <EOL> from grr . lib . flows . general import discovery <EOL> class TestNotifications ( test_lib . GRRSeleniumTest ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def GenerateNotifications ( cls ) : <EOL> """<STR_LIT>""" <EOL> token = access_control . ACLToken ( username = "<STR_LIT:test>" , reason = "<STR_LIT>" ) <EOL> session_id = flow . GRRFlow . StartFlow ( <EOL> client_id = "<STR_LIT>" , <EOL> flow_name = discovery . Interrogate . __name__ , <EOL> token = token ) <EOL> with aff4 . FACTORY . Open ( session_id , mode = "<STR_LIT>" , token = token ) as flow_obj : <EOL> flow_obj . Notify ( "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> flow_obj . Notify ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> flow_obj . Notify ( "<STR_LIT>" , flow_obj . urn , "<STR_LIT>" ) <EOL> flow_obj . GetRunner ( ) . Error ( "<STR_LIT>" ) <EOL> file_urn = "<STR_LIT>" <EOL> with aff4 . FACTORY . Create ( file_urn , "<STR_LIT>" , <EOL> token = token ) as fd : <EOL> fd . Write ( "<STR_LIT:hello>" ) <EOL> flow_obj . Notify ( "<STR_LIT>" , file_urn , "<STR_LIT>" ) <EOL> return session_id <EOL> def setUp ( self ) : <EOL> super ( TestNotifications , self ) . setUp ( ) <EOL> with self . ACLChecksDisabled ( ) : <EOL> self . session_id = self . GenerateNotifications ( ) <EOL> self . RequestAndGrantClientApproval ( "<STR_LIT>" ) <EOL> def testNotifications ( self ) : <EOL> """<STR_LIT>""" <EOL> self . Open ( "<STR_LIT:/>" ) <EOL> self . WaitUntil ( self . IsElementPresent , "<STR_LIT>" ) <EOL> self . WaitUntilEqual ( <EOL> "<STR_LIT>" , self . GetText , "<STR_LIT>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . WaitUntilEqual ( <EOL> "<STR_LIT:0>" , self . GetText , "<STR_LIT>" ) <EOL> self . Open ( "<STR_LIT:/>" ) <EOL> self . WaitUntil ( self . IsElementPresent , "<STR_LIT>" ) <EOL> self . WaitUntilEqual ( "<STR_LIT:0>" , self . GetText , <EOL> "<STR_LIT>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . ClickUntil ( "<STR_LIT>" , <EOL> self . IsElementPresent , "<STR_LIT>" ) <EOL> self . WaitUntilEqual ( "<STR_LIT>" , <EOL> self . GetText , "<STR_LIT>" ) <EOL> self . WaitUntil ( self . IsElementPresent , "<STR_LIT>" ) <EOL> self . WaitUntilContains ( <EOL> "<STR_LIT>" , <EOL> self . GetText , "<STR_LIT>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . WaitUntilContains ( "<STR_LIT>" , <EOL> self . GetText , "<STR_LIT>" ) <EOL> self . ClickUntil ( "<STR_LIT>" , <EOL> self . IsTextPresent , "<STR_LIT>" ) <EOL> self . WaitUntilEqual ( <EOL> "<STR_LIT>" , <EOL> self . GetText , "<STR_LIT>" ) <EOL> self . WaitUntilContains ( <EOL> self . session_id , self . GetText , "<STR_LIT>" ) <EOL> def testUserSettings ( self ) : <EOL> """<STR_LIT>""" <EOL> self . Open ( "<STR_LIT:/>" ) <EOL> self . WaitUntil ( self . IsElementPresent , "<STR_LIT>" ) <EOL> mode_selector = "<STR_LIT>" <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" , self . GetSelectedLabel ( mode_selector ) . strip ( ) ) <EOL> self . Select ( mode_selector , "<STR_LIT>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> "<STR_LIT>" , <EOL> self . GetSelectedLabel ( mode_selector ) . strip ( ) ) <EOL> def testClickOnDownloadFileNotificationLeadsToImmediateFileDownload ( self ) : <EOL> file_urn = "<STR_LIT>" <EOL> with self . ACLChecksDisabled ( ) : <EOL> with aff4 . FACTORY . Create ( file_urn , "<STR_LIT>" , <EOL> token = self . token ) as fd : <EOL> fd . Write ( "<STR_LIT:hello>" ) <EOL> self . _SendNotification ( notification_type = "<STR_LIT>" , <EOL> subject = file_urn , <EOL> message = "<STR_LIT>" ) <EOL> self . Open ( "<STR_LIT:/>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . WaitUntil ( self . FileWasDownloaded ) <EOL> def testServerErrorShowsErrorButton ( self ) : <EOL> from grr . gui . plugins . configuration_view import ConfigFileTableToolbar <EOL> def MockLayout ( self , request , response ) : <EOL> """<STR_LIT>""" <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> with self . ACLChecksDisabled ( ) : <EOL> with utils . Stubber ( ConfigFileTableToolbar , "<STR_LIT>" , MockLayout ) : <EOL> self . Open ( "<STR_LIT:/>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . WaitUntilContains ( "<STR_LIT>" , <EOL> self . GetText , "<STR_LIT>" ) <EOL> self . WaitUntilContains ( "<STR_LIT>" , <EOL> self . GetText , "<STR_LIT>" ) <EOL> def testServerErrorInApiShowsErrorButton ( self ) : <EOL> def MockRender ( self , args , token ) : <EOL> """<STR_LIT>""" <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> with utils . Stubber ( ApiSearchClientsHandler , "<STR_LIT>" , MockRender ) : <EOL> self . Open ( "<STR_LIT:/>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . Click ( "<STR_LIT>" ) <EOL> self . WaitUntilContains ( "<STR_LIT>" , <EOL> self . GetText , <EOL> "<STR_LIT>" ) <EOL> self . WaitUntilContains ( "<STR_LIT>" , <EOL> self . GetText , <EOL> "<STR_LIT>" ) <EOL> def main ( argv ) : <EOL> runtests_test . SeleniumTestProgram ( argv = argv ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> flags . StartMain ( main ) </s>
