Ejemplo n.º 1
0
    def test_cycle_session(self):
        def fn(self, view, app, request, *args, **kwargs):
            return view(app, request, *args, **kwargs)

        def view(app, request):
            request._session.cycle()
            return Response()

        app = pretend.stub(session_store=FakeSessionStore())
        request = pretend.stub(cookies={"session_id": "abcd"}, is_secure=False)

        handle_session(fn)(pretend.stub(), view, app, request)

        assert app.session_store.cycled == [Session({}, "abcd", False)]
Ejemplo n.º 2
0
    def test_existing_session_no_save(self):
        def fn(self, view, app, request, *args, **kwargs):
            return view(app, request, *args, **kwargs)

        view = lambda app, request: Response()
        app = pretend.stub(session_store=FakeSessionStore())
        request = pretend.stub(cookies={"session_id": "abcd"}, is_secure=False)

        response = handle_session(fn)(pretend.stub(), view, app, request)

        assert app.session_store.saved == []
        assert response.headers.getlist("Set-Cookie") == []
Ejemplo n.º 3
0
    def test_existing_session(self):
        def fn(self, view, app, request, *args, **kwargs):
            return view(app, request, *args, **kwargs)

        def view(app, request):
            request._session["wat"] = "ok"
            return Response()

        app = pretend.stub(session_store=FakeSessionStore())
        request = pretend.stub(cookies={"session_id": "abcd"}, is_secure=False)

        response = handle_session(fn)(pretend.stub(), view, app, request)

        assert app.session_store.saved == [
            Session({"wat": "ok"}, "abcd", False),
        ]
        assert response.headers.getlist("Set-Cookie") == [
            "session_id=abcd; HttpOnly; Path=/",
        ]
Ejemplo n.º 4
0
    def test_delete_session(self):
        def fn(self, view, app, request, *args, **kwargs):
            return view(app, request, *args, **kwargs)

        def view(app, request):
            request._session.delete()
            return Response()

        app = pretend.stub(session_store=FakeSessionStore())
        request = pretend.stub(cookies={"session_id": "abcd"}, is_secure=False)

        response = handle_session(fn)(pretend.stub(), view, app, request)

        assert app.session_store.deleted == [
            Session({}, "abcd", False),
        ]
        assert response.headers.getlist("Set-Cookie") == [
            "session_id=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; "
            "Path=/",
        ]