Esempio n. 1
0
    def test_handle_user_input__restart(self, mock_input):
        mock_prompt = 'Mock Prompt: £'
        mock_input.return_value = 'R'
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        with self.assertRaises(UserRequestedRestart):
            result = test_ui._handle_user_input(mock_prompt)

        mock_input.assert_called_once_with(mock_prompt)
Esempio n. 2
0
    def test_handle_user_input__happy_path(self, mock_input):
        mock_prompt = 'Mock Prompt: £'
        mock_input.return_value = '250'
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        result = test_ui._handle_user_input(mock_prompt)

        self.assertEqual(result, Decimal('250'))
        mock_input.assert_called_once_with(mock_prompt)
Esempio n. 3
0
    def test_handle_user_input__exit(self, mock_input, mock_cancel):
        mock_prompt = 'Mock Prompt: £'
        mock_input.return_value = 'Q'
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        with self.assertRaises(SystemExit):
            result = test_ui._handle_user_input(mock_prompt)

        mock_input.assert_called_once_with(mock_prompt)
        mock_cancel.assert_called_once()
Esempio n. 4
0
    def test_handle_user_input__high_payment(self, mock_input, mock_err):
        mock_prompt = 'Mock Prompt: £'
        mock_input.side_effect = ['1500', '250']
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        result = test_ui._handle_user_input(mock_prompt)

        self.assertEqual(result, Decimal('250'))
        self.assertEqual(mock_input.call_count, 2)
        mock_input.assert_called_with(mock_prompt)
        expected_err = 'Payment amount exceeds remaining disposable income. Please enter a valid value.'
        mock_err.assert_called_with(expected_err)
Esempio n. 5
0
    def test_handle_user_input__invalid_input(self, mock_input, mock_err):
        mock_prompt = 'Mock Prompt: £'
        mock_input.side_effect = ['all', '250']
        test_ui = UI()
        test_ui.remaining_disposable = Decimal('1000')

        result = test_ui._handle_user_input(mock_prompt)

        self.assertEqual(result, Decimal('250'))
        self.assertEqual(mock_input.call_count, 2)
        mock_input.assert_called_with(mock_prompt)
        expected_err = 'Please input a valid number or keyboard command.'
        mock_err.assert_called_with(expected_err)