当前位置: 首页>>代码示例>>Python>>正文


Python Session.get_session方法代码示例

本文整理汇总了Python中trac.web.session.Session.get_session方法的典型用法代码示例。如果您正苦于以下问题:Python Session.get_session方法的具体用法?Python Session.get_session怎么用?Python Session.get_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.web.session.Session的用法示例。


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

示例1: test_change_anonymous_session

# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import get_session [as 别名]
    def test_change_anonymous_session(self):
        """
        Verify that changing from one anonymous session to an inexisting
        anonymous session creates the new session and doesn't carry over
        variables from the previous session.
        """

        with self.env.db_transaction as db:
            db("INSERT INTO session VALUES ('123456', 0, 0)")
            db("""
                INSERT INTO session_attribute
                VALUES ('123456', 0, 'foo', 'bar')
                """)

        incookie = Cookie()
        incookie['trac_session'] = '123456'
        req = Mock(authname='anonymous', base_path='/', incookie=incookie,
                   outcookie=Cookie())
        session = Session(self.env, req)
        self.assertEqual({'foo': 'bar'}, session)
        
        session.get_session('7890')
        session['baz'] = 'moo'
        session.save()
        self.assertEqual({'baz': 'moo'}, session)

        with self.env.db_query as db:
            self.assertEqual(1, db("""
                SELECT COUNT(*) FROM session
                WHERE sid='7890' AND authenticated=0
                """)[0][0])
            self.assertEqual([('baz', 'moo')], db("""
                SELECT name, value FROM session_attribute
                WHERE sid='7890' AND authenticated=0
                """))
开发者ID:trac-ja,项目名称:trac-ja,代码行数:37,代码来源:session.py

示例2: test_change_anonymous_session

# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import get_session [as 别名]
    def test_change_anonymous_session(self):
        """
        Verify that changing from one anonymous session to an inexisting
        anonymous session creates the new session and doesn't carry over
        variables from the previous session.
        """

        cursor = self.db.cursor()
        cursor.execute("INSERT INTO session VALUES ('123456', 0, 0)")
        cursor.execute("INSERT INTO session_attribute VALUES "
                       "('123456', 0, 'foo', 'bar')")

        incookie = Cookie()
        incookie['trac_session'] = '123456'
        req = Mock(authname='anonymous', base_path='/', incookie=incookie,
                   outcookie=Cookie())
        session = Session(self.env, req)
        self.assertEqual({'foo': 'bar'}, session)
        
        session.get_session('7890')
        session['baz'] = 'moo'
        session.save()
        self.assertEqual({'baz': 'moo'}, session)

        cursor.execute("SELECT COUNT(*) FROM session WHERE sid='7890' AND "
                       "authenticated=0")
        self.assertEqual(1, cursor.fetchone()[0])
        cursor.execute("SELECT name, value FROM session_attribute "
                       "WHERE sid='7890' AND authenticated=0")
        self.assertEqual([('baz', 'moo')], cursor.fetchall())
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:32,代码来源:session.py

示例3: test_change_anonymous_session

# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import get_session [as 别名]
    def test_change_anonymous_session(self):
        """
        Verify that changing from one anonymous session to an inexisting
        anonymous session creates the new session and doesn't carry over
        variables from the previous session.
        """

        with self.env.db_transaction as db:
            db("INSERT INTO session VALUES ('123456', 0, 0)")
            db(
                """
                INSERT INTO session_attribute
                VALUES ('123456', 0, 'foo', 'bar')
                """
            )

        incookie = Cookie()
        incookie["trac_session"] = "123456"
        req = Mock(authname="anonymous", base_path="/", incookie=incookie, outcookie=Cookie())
        session = Session(self.env, req)
        self.assertEqual({"foo": "bar"}, session)

        session.get_session("7890")
        session["baz"] = "moo"
        session.save()
        self.assertEqual({"baz": "moo"}, session)

        with self.env.db_query as db:
            self.assertEqual(
                1,
                db(
                    """
                SELECT COUNT(*) FROM session
                WHERE sid='7890' AND authenticated=0
                """
                )[0][0],
            )
            self.assertEqual(
                [("baz", "moo")],
                db(
                    """
                SELECT name, value FROM session_attribute
                WHERE sid='7890' AND authenticated=0
                """
                ),
            )
开发者ID:dafrito,项目名称:trac-mirror,代码行数:48,代码来源:session.py

示例4: test_session_get_session_with_invalid_sid

# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import get_session [as 别名]
 def test_session_get_session_with_invalid_sid(self):
     cookie = Cookie()
     req = Mock(incookie=Cookie(), outcookie=cookie, authname='anonymous',
                base_path='/')
     session = Session(self.env, req)
     session.get_session('0123456789')
     self.assertEqual('0123456789', session.sid)
     session.get_session('abcxyz')
     self.assertEqual('abcxyz', session.sid)
     session.get_session('abc123xyz')
     self.assertEqual('abc123xyz', session.sid)
     self.assertRaises(TracError, session.get_session, 'abc 123 xyz')
     self.assertRaises(TracError, session.get_session, 'abc-123-xyz')
     self.assertRaises(TracError, session.get_session, 'abc<i>123</i>xyz')
     self.assertRaises(TracError, session.get_session, u'abc123xÿz')
     self.assertRaises(TracError, session.get_session,
                       u'abc¹₂³xyz')  # Unicode digits
开发者ID:exocad,项目名称:exotrac,代码行数:19,代码来源:session.py


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