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)
Ejemplo n.º 3
0
  def testWarnAboutDestructiveActionRejected(self, rawInputMock):
    # NOTE: rejection can be anything other than the expected input of
    # "Yes-<randint>"
    rawInputMock.return_value = "No"

    with self.assertRaises(delete_companies.UserAbortedOperation):
      delete_companies._warnAboutDestructiveAction(timeout=10,
                                                   tickerSymbols="FOO",
                                                   engineServer="host")
Ejemplo n.º 4
0
  def testWarnAboutDestructiveActionConfirmed(self, randintMock, rawInputMock):
    randintMock.return_value = 1
    rawInputMock.return_value = "Yes-1"

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

    self.assertEqual(rawInputMock.call_count, 1)
    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")
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
  def testWarnAboutDestructiveActionTimedOut(self, rawInputMock):

    # 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.
    rawInputMock.side_effect = lambda *args: time.sleep(10)

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