Example #1
0
    def test_ctrl_c_breaks_execution(self):
        stdin_array = [key.CTRL_C]
        stdin = helper.event_factory(*stdin_array)
        message = "Foo message"
        variable = "Bar variable"

        question = questions.Password(variable, message)

        sut = ConsoleRender(event_generator=stdin)
        with self.assertRaises(KeyboardInterrupt):
            sut.render(question)
Example #2
0
    def test_allows_deletion(self):
        stdin_array = ["a", key.BACKSPACE, "b", key.ENTER]
        stdin = helper.event_factory(*stdin_array)
        message = "Foo message"
        variable = "Bar variable"

        question = questions.Password(variable, message)

        sut = ConsoleRender(event_generator=stdin)
        result = sut.render(question)

        self.assertEqual("b", result)
Example #3
0
    def test_allows_deletion(self):
        stdin_array = ['a', key.BACKSPACE, 'b', key.ENTER]
        stdin = helper.event_factory(*stdin_array)
        message = 'Foo message'
        variable = 'Bar variable'

        question = questions.Password(variable, message)

        sut = ConsoleRender(event_generator=stdin)
        result = sut.render(question)

        self.assertEquals('b', result)
Example #4
0
    def test_do_not_show_values(self):
        stdin = helper.event_factory("m", "y", " ", "p", "a", "s", "s", "w",
                                     "o", "r", "d", key.ENTER)
        message = "Foo message"
        variable = "Bar variable"

        question = questions.Password(variable, message)

        sut = ConsoleRender(event_generator=stdin)
        sut.render(question)

        self.assertInStdout(message)
        self.assertNotInStdout("my password")
Example #5
0
    def test_validate_custom_error(self):
        stdin = helper.event_factory('p', 'a', 's', 's', key.ENTER)
        message = 'Foo message'
        variable = 'Bar variable'

        def validate(answers, current):
            raise inquirer.errors.ValidationError('', reason='')

        question = questions.Password(variable, message, validate=validate)

        sut = ConsoleRender(event_generator=stdin)
        with self.assertRaises(StopIteration):
            sut.render(question)
Example #6
0
    def test_validate(self):
        stdin = helper.event_factory('p', 'a', 's', 's', key.ENTER)
        message = 'Foo message'
        variable = 'Bar variable'

        def validate(answers, current):
            return False

        question = questions.Password(variable, message, validate=validate)

        sut = ConsoleRender(event_generator=stdin)
        with self.assertRaises(StopIteration):
            sut.render(question)
Example #7
0
    def test_do_not_show_values(self):
        stdin = helper.event_factory('m', 'y', ' ', 'p', 'a', 's', 's', 'w',
                                     'o', 'r', 'd', key.ENTER)
        message = 'Foo message'
        variable = 'Bar variable'

        question = questions.Password(variable, message)

        sut = ConsoleRender(event_generator=stdin)
        sut.render(question)

        self.assertInStdout(message)
        self.assertNotInStdout('my password')
Example #8
0
    def test_cursor_movement(self):
        stdin_array = [
            "a",
            key.UP,
            "b",
            key.DOWN,
            "c",
            key.LEFT,
            "d",
            key.RIGHT,
            "e",
            key.ENTER,
        ]
        stdin = helper.event_factory(*stdin_array)
        message = "Foo message"
        variable = "Bar variable"

        question = questions.Password(variable, message)

        sut = ConsoleRender(event_generator=stdin)
        result = sut.render(question)

        self.assertEqual("abdce", result)
Example #9
0
    def test_cursor_movement(self):
        stdin_array = [
            'a',
            key.UP,
            'b',
            key.DOWN,
            'c',
            key.LEFT,
            'd',
            key.RIGHT,
            'e',
            key.ENTER,
        ]
        stdin = helper.event_factory(*stdin_array)
        message = 'Foo message'
        variable = 'Bar variable'

        question = questions.Password(variable, message)

        sut = ConsoleRender(event_generator=stdin)
        result = sut.render(question)

        self.assertEqual('abdce', result)
Example #10
0
def password(message, render=None, **kwargs):
    render = render or ConsoleRender()
    question = questions.Password(name="", message=message, **kwargs)
    return render.render(question)