Esempio n. 1
0
    def test_validate_macaroon_id(self):
        macaroon_service = pretend.stub(
            find_macaroon=pretend.call_recorder(lambda id: pretend.stub()))
        form = forms.DeleteMacaroonForm(data={"macaroon_id": pretend.stub()},
                                        macaroon_service=macaroon_service)

        assert form.validate()
Esempio n. 2
0
    def test_validate_macaroon_id_invalid(self):
        macaroon_service = pretend.stub(
            find_macaroon=pretend.call_recorder(lambda id: None))
        form = forms.DeleteMacaroonForm(data={"macaroon_id": pretend.stub()},
                                        macaroon_service=macaroon_service)

        assert not form.validate()
        assert form.macaroon_id.errors.pop() == "No such macaroon"
Esempio n. 3
0
    def test_creation(self):
        macaroon_service = pretend.stub()
        user_service = pretend.stub()
        form = forms.DeleteMacaroonForm(macaroon_service=macaroon_service,
                                        user_service=user_service)

        assert form.macaroon_service is macaroon_service
        assert form.user_service is user_service
Esempio n. 4
0
    def test_validate_macaroon_id(self):
        macaroon_service = pretend.stub(
            find_macaroon=pretend.call_recorder(lambda id: pretend.stub())
        )
        user_service = pretend.stub(
            find_userid=lambda *a, **kw: 1, check_password=lambda *a, **kw: True
        )
        form = forms.DeleteMacaroonForm(
            data={"macaroon_id": pretend.stub(), "password": "******"},
            macaroon_service=macaroon_service,
            username="******",
            user_service=user_service,
        )

        assert form.validate()
Esempio n. 5
0
    def test_validate_macaroon_id_invalid(self):
        macaroon_service = pretend.stub(
            find_macaroon=pretend.call_recorder(lambda id: None))
        user_service = pretend.stub(find_userid=lambda *a, **kw: 1,
                                    check_password=lambda *a, **kw: True)
        request = pretend.stub(remote_addr="1.2.3.4")
        form = forms.DeleteMacaroonForm(
            data={
                "macaroon_id": pretend.stub(),
                "password": "******"
            },
            request=request,
            macaroon_service=macaroon_service,
            user_service=user_service,
            username="******",
        )

        assert not form.validate()
        assert form.macaroon_id.errors.pop() == "No such macaroon"