• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sessions.SessionFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中warehouse.sessions.SessionFactory的典型用法代码示例。如果您正苦于以下问题:Python SessionFactory类的具体用法?Python SessionFactory怎么用?Python SessionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SessionFactory类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_valid_session_id_invalid_data

    def test_valid_session_id_invalid_data(self, pyramid_request):
        pyramid_request.cookies["session_id"] = "123456"

        session_factory = SessionFactory(
            "mysecret", "redis://redis://localhost:6379/0",
        )
        session_factory.signer.unsign = pretend.call_recorder(
            lambda session_id, max_age: b"123456"
        )
        session_factory.redis = pretend.stub(
            get=pretend.call_recorder(lambda key: b"invalid data"),
        )
        session_factory._process_response = pretend.stub()
        session = session_factory(pyramid_request)

        assert len(pyramid_request.response_callbacks) == 1
        assert pyramid_request.response_callbacks[0] is \
            session_factory._process_response

        assert session_factory.signer.unsign.calls == [
            pretend.call("123456", max_age=12 * 60 * 60),
        ]

        assert session_factory.redis.get.calls == [
            pretend.call("warehouse/session/data/123456"),
        ]

        assert isinstance(session, Session)
        assert session._sid is None
        assert session.new
开发者ID:mbacchi,项目名称:warehouse,代码行数:30,代码来源:test_sessions.py


示例2: test_invalidated_deletes_no_save

    def test_invalidated_deletes_no_save(self, pyramid_request):
        session_factory = SessionFactory(
            "mysecret", "redis://redis://localhost:6379/0",
        )
        session_factory.redis = pretend.stub(
            delete=pretend.call_recorder(lambda key: None)
        )
        pyramid_request.session.invalidated = ["1", "2"]
        pyramid_request.session.should_save = pretend.call_recorder(
            lambda: False
        )
        response = pretend.stub(
            delete_cookie=pretend.call_recorder(lambda cookie: None),
        )
        session_factory._process_response(pyramid_request, response)

        assert session_factory.redis.delete.calls == [
            pretend.call("warehouse/session/data/1"),
            pretend.call("warehouse/session/data/2"),
        ]
        assert pyramid_request.session.should_save.calls == [
            pretend.call(),
            pretend.call(),
        ]
        assert response.delete_cookie.calls == [pretend.call("session_id")]
开发者ID:mbacchi,项目名称:warehouse,代码行数:25,代码来源:test_sessions.py


示例3: test_no_save_invalid_session

 def test_no_save_invalid_session(self, pyramid_request):
     session_factory = SessionFactory(
         "mysecret", "redis://redis://localhost:6379/0",
     )
     session_factory.redis = pretend.stub()
     pyramid_request.session = InvalidSession()
     response = pretend.stub()
     session_factory._process_response(pyramid_request, response)
开发者ID:mbacchi,项目名称:warehouse,代码行数:8,代码来源:test_sessions.py


示例4: test_noop_unused_session

 def test_noop_unused_session(self, pyramid_request):
     session_factory = SessionFactory("mysecret", "redis://redis://localhost:6379/0")
     session_factory.redis = pretend.stub()
     pyramid_request.session.invalidated = set()
     pyramid_request.session.should_save = pretend.call_recorder(lambda: False)
     response = pretend.stub()
     session_factory._process_response(pyramid_request, response)
     assert pyramid_request.session.should_save.calls == [pretend.call()]
开发者ID:dstufft,项目名称:warehouse,代码行数:8,代码来源:test_sessions.py


示例5: test_no_current_session

    def test_no_current_session(self, pyramid_request):
        session_factory = SessionFactory("mysecret", "redis://redis://localhost:6379/0")
        session_factory._process_response = pretend.stub()
        session = session_factory(pyramid_request)

        assert len(pyramid_request.response_callbacks) == 1
        assert (
            pyramid_request.response_callbacks[0] is session_factory._process_response
        )

        assert isinstance(session, Session)
        assert session._sid is None
        assert session.new
开发者ID:dstufft,项目名称:warehouse,代码行数:13,代码来源:test_sessions.py


示例6: test_invalid_session_id

    def test_invalid_session_id(self, pyramid_request):
        pyramid_request.cookies["session_id"] = "invalid!"

        session_factory = SessionFactory("mysecret", "redis://redis://localhost:6379/0")
        session_factory._process_response = pretend.stub()
        session = session_factory(pyramid_request)

        assert len(pyramid_request.response_callbacks) == 1
        assert (
            pyramid_request.response_callbacks[0] is session_factory._process_response
        )

        assert isinstance(session, Session)
        assert session._sid is None
        assert session.new
开发者ID:dstufft,项目名称:warehouse,代码行数:15,代码来源:test_sessions.py


示例7: test_invalidated_deletes_save_non_secure

    def test_invalidated_deletes_save_non_secure(self, monkeypatch, pyramid_request):
        msgpack_packb = pretend.call_recorder(
            lambda data, encoding, use_bin_type: b"msgpack data"
        )
        monkeypatch.setattr(msgpack, "packb", msgpack_packb)

        session_factory = SessionFactory("mysecret", "redis://redis://localhost:6379/0")
        session_factory.redis = pretend.stub(
            delete=pretend.call_recorder(lambda key: None),
            setex=pretend.call_recorder(lambda key, age, data: None),
        )
        session_factory.signer.sign = pretend.call_recorder(lambda data: "cookie data")
        pyramid_request.scheme = "http"
        pyramid_request.session.sid = "123456"
        pyramid_request.session.invalidated = ["1", "2"]
        pyramid_request.session.should_save = pretend.call_recorder(lambda: True)
        response = pretend.stub(
            set_cookie=pretend.call_recorder(
                lambda cookie, data, max_age, httponly, secure, samesite: None
            )
        )
        session_factory._process_response(pyramid_request, response)

        assert session_factory.redis.delete.calls == [
            pretend.call("warehouse/session/data/1"),
            pretend.call("warehouse/session/data/2"),
        ]
        assert msgpack_packb.calls == [
            pretend.call(pyramid_request.session, encoding="utf8", use_bin_type=True)
        ]
        assert session_factory.redis.setex.calls == [
            pretend.call("warehouse/session/data/123456", 12 * 60 * 60, b"msgpack data")
        ]
        assert pyramid_request.session.should_save.calls == [
            pretend.call(),
            pretend.call(),
        ]
        assert session_factory.signer.sign.calls == [pretend.call(b"123456")]
        assert response.set_cookie.calls == [
            pretend.call(
                "session_id",
                "cookie data",
                max_age=12 * 60 * 60,
                httponly=True,
                secure=False,
                samesite=b"lax",
            )
        ]
开发者ID:dstufft,项目名称:warehouse,代码行数:48,代码来源:test_sessions.py


示例8: test_valid_session_id_valid_data

    def test_valid_session_id_valid_data(self, monkeypatch, pyramid_request):
        msgpack_unpackb = pretend.call_recorder(
            lambda bdata, encoding, use_list: {"foo": "bar"}
        )
        monkeypatch.setattr(msgpack, "unpackb", msgpack_unpackb)

        pyramid_request.cookies["session_id"] = "123456"

        session_factory = SessionFactory(
            "mysecret", "redis://redis://localhost:6379/0",
        )
        session_factory.signer.unsign = pretend.call_recorder(
            lambda session_id, max_age: b"123456"
        )
        session_factory.redis = pretend.stub(
            get=pretend.call_recorder(lambda key: b"valid data"),
        )
        session_factory._process_response = pretend.stub()
        session = session_factory(pyramid_request)

        assert len(pyramid_request.response_callbacks) == 1
        assert pyramid_request.response_callbacks[0] is \
            session_factory._process_response

        assert session_factory.signer.unsign.calls == [
            pretend.call("123456", max_age=12 * 60 * 60),
        ]

        assert session_factory.redis.get.calls == [
            pretend.call("warehouse/session/data/123456"),
        ]

        assert msgpack_unpackb.calls == [
            pretend.call(b"valid data", encoding="utf8", use_list=True),
        ]

        assert isinstance(session, Session)
        assert session == {"foo": "bar"}
        assert session.sid == "123456"
        assert not session.new
开发者ID:mbacchi,项目名称:warehouse,代码行数:40,代码来源:test_sessions.py


示例9: test_redis_key

 def test_redis_key(self):
     session_factory = SessionFactory(
         "mysecret", "redis://redis://localhost:6379/0",
     )
     assert session_factory._redis_key("my_session_id") == \
         "warehouse/session/data/my_session_id"
开发者ID:mbacchi,项目名称:warehouse,代码行数:6,代码来源:test_sessions.py



注:本文中的warehouse.sessions.SessionFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python views.search函数代码示例发布时间:2022-05-26
下一篇:
Python sessions.Session类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap