Exemplo n.º 1
0
    def test_validate_password_no_user(self):
        login_service = pretend.stub(
            find_userid=pretend.call_recorder(lambda userid: None),
        )
        form = LoginForm(
            data={"username": "******"},
            login_service=login_service,
        )
        field = pretend.stub(data="password")

        form.validate_password(field)

        assert login_service.find_userid.calls == [pretend.call("my_username")]
Exemplo n.º 2
0
    def test_validate_password_ok(self):
        login_service = pretend.stub(
            find_userid=pretend.call_recorder(lambda userid: 1),
            check_password=pretend.call_recorder(
                lambda userid, password: True
            ),
        )
        form = LoginForm(
            data={"username": "******"},
            login_service=login_service,
        )
        field = pretend.stub(data="pw")

        form.validate_password(field)

        assert login_service.find_userid.calls == [pretend.call("my_username")]
        assert login_service.check_password.calls == [pretend.call(1, "pw")]
Exemplo n.º 3
0
    def test_validate_password_notok(self, db_session):
        login_service = pretend.stub(
            find_userid=pretend.call_recorder(lambda userid: 1),
            check_password=pretend.call_recorder(
                lambda userid, password: False
            ),
        )
        form = LoginForm(
            data={"username": "******"},
            login_service=login_service,
        )
        field = pretend.stub(data="pw")

        with pytest.raises(wtforms.validators.ValidationError):
            form.validate_password(field)

        assert login_service.find_userid.calls == [pretend.call("my_username")]
        assert login_service.check_password.calls == [pretend.call(1, "pw")]