예제 #1
0
    def test_session_view(self, monkeypatch, pyramid_request):
        class FakeMapper:
            def __call__(self, view):
                return view

        mapper = session_mapper_factory(FakeMapper)()

        context = pretend.stub()
        request = pyramid_request
        request._allow_session = True

        session = request.session

        @pretend.call_recorder
        def view(context, request):
            assert request.session is session

        wrapped = mapper(view)
        wrapped(context, request)

        assert view.calls == [pretend.call(context, request)]
        assert request.session is session
예제 #2
0
    def test_session_view(self, monkeypatch, pyramid_request):
        class FakeMapper:
            def __call__(self, view):
                return view

        mapper = session_mapper_factory(FakeMapper)()

        context = pretend.stub()
        request = pyramid_request
        request._allow_session = True

        session = request.session

        @pretend.call_recorder
        def view(context, request):
            assert request.session is session

        wrapped = mapper(view)
        wrapped(context, request)

        assert view.calls == [pretend.call(context, request)]
        assert request.session is session
예제 #3
0
    def test_non_session_view(self, monkeypatch):
        class FakeMapper:
            def __call__(self, view):
                return view

        mapper = session_mapper_factory(FakeMapper)()

        context = pretend.stub()
        request = pretend.stub(session=Session())

        session = request.session

        @pretend.call_recorder
        def view(context, request):
            assert request.session is not session
            assert isinstance(request.session, InvalidSession)

        wrapped = mapper(view)
        wrapped(context, request)

        assert view.calls == [pretend.call(context, request)]
        assert isinstance(request.session, InvalidSession)
예제 #4
0
    def test_non_session_view(self, monkeypatch):
        class FakeMapper:
            def __call__(self, view):
                return view

        mapper = session_mapper_factory(FakeMapper)()

        context = pretend.stub()
        request = pretend.stub(session=Session())

        session = request.session

        @pretend.call_recorder
        def view(context, request):
            assert request.session is not session
            assert isinstance(request.session, InvalidSession)

        wrapped = mapper(view)
        wrapped(context, request)

        assert view.calls == [pretend.call(context, request)]
        assert isinstance(request.session, InvalidSession)