def testWarnAboutDestructiveActionRejected(self, promptWithTimeoutMock):
        # NOTE: rejection can be anything other than the expected input of
        # "Yes-<randint>"
        promptWithTimeoutMock.return_value = "No"

        with self.assertRaises(delete_companies.UserAbortedOperation):
            delete_companies._warnAboutDestructiveAction(timeout=10,
                                                         tickerSymbols="FOO",
                                                         engineServer="host")
  def testWarnAboutDestructiveActionRejected(self, promptWithTimeoutMock):
    # NOTE: rejection can be anything other than the expected input of
    # "Yes-<randint>"
    promptWithTimeoutMock.return_value = "No"

    with self.assertRaises(delete_companies.UserAbortedOperation):
      delete_companies._warnAboutDestructiveAction(timeout=10,
                                                   tickerSymbols="FOO",
                                                   engineServer="host")
    def testWarnAboutDestructiveActionConfirmed(self, randintMock,
                                                promptWithTimeoutMock):
        randintMock.return_value = 1
        promptWithTimeoutMock.return_value = "Yes-1"

        delete_companies._warnAboutDestructiveAction(timeout=10,
                                                     tickerSymbols="FOO",
                                                     engineServer="host")

        promptWithTimeoutMock.assert_called_once_with(promptText=ANY,
                                                      timeout=10)
  def testWarnAboutDestructiveActionConfirmed(self, randintMock,
                                              promptWithTimeoutMock):
    randintMock.return_value = 1
    promptWithTimeoutMock.return_value = "Yes-1"

    delete_companies._warnAboutDestructiveAction(timeout=10,
                                                 tickerSymbols="FOO",
                                                 engineServer="host")

    promptWithTimeoutMock.assert_called_once_with(promptText=ANY,
                                                  timeout=10)
    def testWarnAboutDestructiveActionTimedOut(self, promptWithTimeoutMock):

        # NOTE: py.test by default captures console output and patches console input
        # such that raw_input fails. Although not ideal, we have to patch
        # raw_input with something else that blocks and will be interrupted by
        # SIGINT.
        promptWithTimeoutMock.side_effect = prompt_utils.PromptTimeout

        with self.assertRaises(delete_companies.WarningPromptTimeout):
            delete_companies._warnAboutDestructiveAction(timeout=0.001,
                                                         tickerSymbols="FOO",
                                                         engineServer="host")
  def testWarnAboutDestructiveActionTimedOut(self, promptWithTimeoutMock):

    # NOTE: py.test by default captures console output and patches console input
    # such that raw_input fails. Although not ideal, we have to patch
    # raw_input with something else that blocks and will be interrupted by
    # SIGINT.
    promptWithTimeoutMock.side_effect = prompt_utils.PromptTimeout

    with self.assertRaises(delete_companies.WarningPromptTimeout):
      delete_companies._warnAboutDestructiveAction(timeout=0.001,
                                                   tickerSymbols="FOO",
                                                   engineServer="host")