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')

[((8, 5, 8, 28), 'unittest.mock.patch', 'patch', ({(8, 11, 8, 27): '"""builtins.input"""'}, {}), "('builtins.input')", False, 'from unittest.mock import patch\n'), ((15, 5, 15, 28), 'unittest.mock.patch', 'patch', ({(15, 11, 15, 27): '"""builtins.input"""'}, {}), "('builtins.input')", False, 'from unittest.mock import patch\n'), ((16, 5, 16, 28), 'unittest.mock.patch', 'patch', ({(16, 11, 16, 27): '"""builtins.print"""'}, {}), "('builtins.print')", False, 'from unittest.mock import patch\n'), ((11, 26, 11, 66), 'easy2fa.cli.check_input', 'cli.check_input', (), '', False, 'from easy2fa import cli\n'), ((13, 26, 13, 66), 'easy2fa.cli.check_input', 'cli.check_input', (), '', False, 'from easy2fa import cli\n'), ((23, 26, 23, 72), 'easy2fa.cli.check_input', 'cli.check_input', (), '', False, 'from easy2fa import cli\n')]