Пример #1
0
def test_wizard_previous_first_step(mocker):
    mocked_app = mocker.MagicMock()
    mocker.patch('interrogatio.widgets.wizard.get_app',
                 return_value=mocked_app)
    questions = [
        {
            'name': 'question1',
            'type': 'input',
            'message': 'message',
            'description': 'description',
            'validators': [{
                'name': 'required'
            }],
        },
        {
            'name': 'question2',
            'type': 'input',
            'message': 'message',
            'description': 'description',
            'validators': [{
                'name': 'required'
            }],
        },
    ]
    handlers = [get_instance(q) for q in questions]
    mocker.patch.object(WizardDialog, 'validate')
    wz = WizardDialog('title', handlers)
    wz.next()  # noqa: B305
    wz.previous()
    wz.previous()
    assert wz.current_step_idx == 0
    assert wz.current_step == wz.steps[0]
    assert len(wz.buttons) == 2
    assert wz.previous_btn not in wz.buttons
Пример #2
0
def test_wizard_next_latest_step(mocker):
    mocked_app = mocker.MagicMock()
    mocker.patch('interrogatio.widgets.wizard.get_app',
                 return_value=mocked_app)
    questions = [
        {
            'name': 'question1',
            'type': 'input',
            'message': 'message',
            'description': 'description',
            'validators': [{
                'name': 'required'
            }],
        },
        {
            'name': 'question2',
            'type': 'input',
            'message': 'message',
            'description': 'description',
            'validators': [{
                'name': 'required'
            }],
        },
    ]
    handlers = [get_instance(q) for q in questions]
    mocked_validate = mocker.patch.object(WizardDialog, 'validate')
    wz = WizardDialog('title', handlers)
    wz.next()  # noqa: B305
    wz.next()  # noqa: B305
    assert wz.current_step_idx == 1
    assert wz.current_step == wz.steps[1]
    assert len(wz.buttons) == 3
    assert wz.previous_btn in wz.buttons
    assert mocked_validate.call_count == 2
    mocked_app.exit.assert_called_once_with(result=True)
Пример #3
0
def test_wizard_next_validate_invalid(mocker):
    mocked_app = mocker.MagicMock()
    mocker.patch('interrogatio.widgets.wizard.get_app',
                 return_value=mocked_app)
    questions = [
        {
            'name': 'question1',
            'type': 'input',
            'message': 'message',
            'description': 'description',
            'validators': [RequiredValidator('This field is required')],
        },
    ]
    handlers = [get_instance(q) for q in questions]
    wz = WizardDialog('title', handlers)
    wz.next()  # noqa: B305
    assert wz.current_step_idx == 0
    assert wz.current_step == wz.steps[0]
    assert len(wz.buttons) == 2
    assert wz.error_messages == 'This field is required'
Пример #4
0
def test_single_step(mocker):
    mocked_app = mocker.MagicMock()
    mocker.patch('interrogatio.widgets.wizard.get_app',
                 return_value=mocked_app)
    questions = [
        {
            'name': 'question1',
            'type': 'input',
            'message': 'message',
            'description': 'description',
        },
    ]
    handlers = [get_instance(q) for q in questions]
    wz = WizardDialog('title', handlers)
    wz.next()  # noqa: B305
    assert wz.current_step_idx == 0
    assert wz.current_step == wz.steps[0]
    assert len(wz.buttons) == 2
    assert wz.previous_btn not in wz.buttons
    mocked_app.exit.assert_called_once_with(result=True)