Exemplo n.º 1
0
    def test_invalid_with_inactive_user(self, pyramid_csrf_request, user_service):
        schema = LoginSchema().bind(request=pyramid_csrf_request)
        user_service.fetch_for_login.side_effect = UserNotActivated()

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({"username": "******", "password": "******"})
        errors = exc.value.asdict()

        assert "username" in errors
        assert "activate your account" in errors["username"]
Exemplo n.º 2
0
    def test_invalid_with_unknown_user(self, pyramid_csrf_request, user_service):
        schema = LoginSchema().bind(request=pyramid_csrf_request)
        user_service.fetch_for_login.return_value = None

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({"username": "******", "password": "******"})
        errors = exc.value.asdict()

        assert "username" in errors
        assert "does not exist" in errors["username"]
Exemplo n.º 3
0
    def test_passes_password_to_user_password_service(
        self, factories, pyramid_csrf_request, user_service, user_password_service
    ):
        user = factories.User.build(username="******")
        user_service.fetch_for_login.return_value = user
        schema = LoginSchema().bind(request=pyramid_csrf_request)

        schema.deserialize({"username": "******", "password": "******"})

        user_password_service.check_password.assert_called_once_with(user, "cake")
Exemplo n.º 4
0
    def test_invalid_with_inactive_user(self, pyramid_csrf_request,
                                        user_service):
        schema = LoginSchema().bind(request=pyramid_csrf_request)
        user_service.fetch_for_login.side_effect = UserNotActivated()

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({"username": "******", "password": "******"})
        errors = exc.value.asdict()

        assert "username" in errors
        assert "activate your account" in errors["username"]
Exemplo n.º 5
0
    def test_passes_username_to_user_service(self, factories,
                                             pyramid_csrf_request,
                                             user_service):
        user = factories.User.build(username="******")
        user_service.fetch_for_login.return_value = user
        schema = LoginSchema().bind(request=pyramid_csrf_request)

        schema.deserialize({"username": "******", "password": "******"})

        user_service.fetch_for_login.assert_called_once_with(
            username_or_email="jeannie")
Exemplo n.º 6
0
    def test_invalid_with_bad_password(self, factories, pyramid_csrf_request,
                                       user_service, user_password_service):
        user = factories.User.build(username="******")
        user_service.fetch_for_login.return_value = user
        user_password_service.check_password.return_value = False
        schema = LoginSchema().bind(request=pyramid_csrf_request)

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({"username": "******", "password": "******"})
        errors = exc.value.asdict()

        assert "password" in errors
        assert "Wrong password" in errors["password"]
Exemplo n.º 7
0
    def test_invalid_with_unknown_user(self, pyramid_csrf_request,
                                       user_service):
        schema = LoginSchema().bind(request=pyramid_csrf_request)
        user_service.fetch_for_login.return_value = None

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({
                'username': '******',
                'password': '******',
            })
        errors = exc.value.asdict()

        assert 'username' in errors
        assert 'does not exist' in errors['username']
Exemplo n.º 8
0
    def test_invalid_with_inactive_user(self, pyramid_csrf_request,
                                        user_service):
        schema = LoginSchema().bind(request=pyramid_csrf_request)
        user_service.fetch_for_login.side_effect = UserNotActivated()

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({
                'username': '******',
                'password': '******',
            })
        errors = exc.value.asdict()

        assert 'username' in errors
        assert 'activate your account' in errors['username']
Exemplo n.º 9
0
    def test_invalid_with_bad_password(
        self, factories, pyramid_csrf_request, user_service, user_password_service
    ):
        user = factories.User.build(username="******")
        user_service.fetch_for_login.return_value = user
        user_password_service.check_password.return_value = False
        schema = LoginSchema().bind(request=pyramid_csrf_request)

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({"username": "******", "password": "******"})
        errors = exc.value.asdict()

        assert "password" in errors
        assert "Wrong password" in errors["password"]
Exemplo n.º 10
0
    def test_passes_password_to_user_password_service(self, factories,
                                                      pyramid_csrf_request,
                                                      user_service,
                                                      user_password_service):
        user = factories.User.build(username='******')
        user_service.fetch_for_login.return_value = user
        schema = LoginSchema().bind(request=pyramid_csrf_request)

        schema.deserialize({
            'username': '******',
            'password': '******',
        })

        user_password_service.check_password.assert_called_once_with(
            user, 'cake')
Exemplo n.º 11
0
    def test_it_returns_user_when_valid(
        self, factories, pyramid_csrf_request, user_service
    ):
        user = factories.User.build(username="******")
        user_service.fetch_for_login.return_value = user
        schema = LoginSchema().bind(request=pyramid_csrf_request)

        result = schema.deserialize({"username": "******", "password": "******"})

        assert result["user"] is user
Exemplo n.º 12
0
    def test_it_returns_user_when_valid(self, factories, pyramid_csrf_request,
                                        user_service):
        user = factories.User.build(username='******')
        user_service.fetch_for_login.return_value = user
        schema = LoginSchema().bind(request=pyramid_csrf_request)

        result = schema.deserialize({
            'username': '******',
            'password': '******',
        })

        assert result['user'] is user
Exemplo n.º 13
0
    def test_it_returns_user_when_valid(self, factories, pyramid_csrf_request,
                                        user_service):
        user = factories.User.build(username="******")
        user_service.fetch_for_login.return_value = user
        schema = LoginSchema().bind(request=pyramid_csrf_request)

        result = schema.deserialize({
            "username": "******",
            "password": "******"
        })

        assert result["user"] is user
Exemplo n.º 14
0
    def test_invalid_with_bad_csrf(self, pyramid_request, user_service):
        schema = LoginSchema().bind(request=pyramid_request)

        with pytest.raises(BadCSRFToken):
            schema.deserialize({"username": "******", "password": "******"})
Exemplo n.º 15
0
    def test_invalid_with_bad_csrf(self, pyramid_request, user_service):
        schema = LoginSchema().bind(request=pyramid_request)

        with pytest.raises(BadCSRFToken):
            schema.deserialize({"username": "******", "password": "******"})