Esempio n. 1
0
    def test_resets_password_bad_confirm(self, db_request, monkeypatch):
        user = UserFactory.create()

        db_request.matchdict["user_id"] = str(user.id)
        db_request.params = {"username": "******"}
        db_request.route_path = pretend.call_recorder(
            lambda *a, **kw: "/foobar")
        db_request.user = UserFactory.create()
        service = pretend.stub(
            find_userid=pretend.call_recorder(lambda username: user.id),
            disable_password=pretend.call_recorder(
                lambda userid, reason: None),
        )
        db_request.find_service = pretend.call_recorder(
            lambda iface, context: service)

        send_email = pretend.call_recorder(lambda *a, **kw: None)
        monkeypatch.setattr(views, "send_password_compromised_email",
                            send_email)

        result = views.user_reset_password(db_request)

        assert db_request.find_service.calls == []
        assert send_email.calls == []
        assert service.disable_password.calls == []
        assert db_request.route_path.calls == [
            pretend.call("admin.user.detail", user_id=user.id)
        ]
        assert result.status_code == 303
        assert result.location == "/foobar"
Esempio n. 2
0
    def test_resets_password_bad_confirm(self, db_request, monkeypatch):
        user = UserFactory.create()

        db_request.matchdict["user_id"] = str(user.id)
        db_request.params = {"username": "******"}
        db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/foobar")
        db_request.user = UserFactory.create()
        db_request.remote_addr = "10.10.10.10"
        service = pretend.stub(
            find_userid=pretend.call_recorder(lambda username: user.id),
            disable_password=pretend.call_recorder(lambda userid, reason: None),
        )
        db_request.find_service = pretend.call_recorder(lambda iface, context: service)

        send_email = pretend.call_recorder(lambda *a, **kw: None)
        monkeypatch.setattr(views, "send_password_compromised_email", send_email)

        result = views.user_reset_password(db_request)

        assert db_request.find_service.calls == []
        assert send_email.calls == []
        assert service.disable_password.calls == []
        assert db_request.route_path.calls == [
            pretend.call("admin.user.detail", user_id=user.id)
        ]
        assert result.status_code == 303
        assert result.location == "/foobar"