from unittest import TestCase
from unittest.mock import patch

from easy2fa import cli


class TestCheckInput(TestCase):
    @patch('builtins.input')
    def test_default(self, mock_input):
        mock_input.return_value = ''
        self.assertEquals(cli.check_input('prompt', default='one'), 'one')
        mock_input.return_value = 'two'
        self.assertEquals(cli.check_input('prompt', default='one'), 'two')

    @patch('builtins.input')
    @patch('builtins.print')
    def test_assertions(self, mock_print, mock_input):
        def assertion(value):
            if value not in ['yes', 'no']:
                return 'use yes or no'

        mock_input.side_effect = ['input', '', 'no']
        self.assertEquals(cli.check_input('prompt', assertion=assertion),
                          'no')
        mock_print.assert_called_with('\tInvalid input: use yes or no')

[((126, 149), 'unittest.mock.patch', 'patch', (['"""builtins.input"""'], {}), "('builtins.input')\n", (131, 149), False, 'from unittest.mock import patch\n'), ((423, 446), 'unittest.mock.patch', 'patch', (['"""builtins.input"""'], {}), "('builtins.input')\n", (428, 446), False, 'from unittest.mock import patch\n'), ((452, 475), 'unittest.mock.patch', 'patch', (['"""builtins.print"""'], {}), "('builtins.print')\n", (457, 475), False, 'from unittest.mock import patch\n'), ((253, 293), 'easy2fa.cli.check_input', 'cli.check_input', (['"""prompt"""'], {'default': '"""one"""'}), "('prompt', default='one')\n", (268, 293), False, 'from easy2fa import cli\n'), ((368, 408), 'easy2fa.cli.check_input', 'cli.check_input', (['"""prompt"""'], {'default': '"""one"""'}), "('prompt', default='one')\n", (383, 408), False, 'from easy2fa import cli\n'), ((723, 769), 'easy2fa.cli.check_input', 'cli.check_input', (['"""prompt"""'], {'assertion': 'assertion'}), "('prompt', assertion=assertion)\n", (738, 769), False, 'from easy2fa import cli\n')]