本文整理汇总了Python中trac.web.session.Session.save方法的典型用法代码示例。如果您正苦于以下问题:Python Session.save方法的具体用法?Python Session.save怎么用?Python Session.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.web.session.Session
的用法示例。
在下文中一共展示了Session.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_change_anonymous_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [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())
示例2: test_delete_empty_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_delete_empty_session(self):
"""
Verify that a session gets deleted when it doesn't have any data except
for the 'last_visit' timestamp.
"""
now = time.time()
# Make sure the session has data so that it doesn't get dropped
cursor = self.db.cursor()
cursor.execute("INSERT INTO session "
"VALUES ('123456', 0, %s)",
(int(now - UPDATE_INTERVAL - 3600),))
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)
del session['foo']
session.save()
cursor.execute("SELECT COUNT(*) FROM session WHERE sid='123456' AND "
"authenticated=0")
self.assertEqual(0, cursor.fetchone()[0])
示例3: test_purge_anonymous_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_purge_anonymous_session(self):
"""
Verify that old sessions get purged.
"""
with self.env.db_transaction as db:
db("INSERT INTO session VALUES ('123456', 0, %s)", (0,))
db("INSERT INTO session VALUES ('987654', 0, %s)",
(int(time.time() - PURGE_AGE - 3600),))
db("""
INSERT INTO session_attribute
VALUES ('987654', 0, 'foo', 'bar')
""")
# We need to modify a different session to trigger the purging
incookie = Cookie()
incookie['trac_session'] = '123456'
req = Mock(authname='anonymous', base_path='/', incookie=incookie,
outcookie=Cookie())
session = Session(self.env, req)
session['foo'] = 'bar'
session.save()
self.assertEqual(0, self.env.db_query("""
SELECT COUNT(*) FROM session WHERE sid='987654' AND authenticated=0
""")[0][0])
示例4: test_authenticated_session_independence_var
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_authenticated_session_independence_var(self):
"""
Verify that an anonymous session with the same name as an authenticated
session doesn't interfere with the latter.
"""
cursor = self.db.cursor()
cursor.execute("INSERT INTO session VALUES ('john', 1, 0)")
cursor.execute("INSERT INTO session_attribute VALUES "
"('john', 1, 'foo', 'bar')")
cursor.execute("SELECT value FROM session_attribute "
"WHERE sid='john' AND authenticated=1 AND name='foo'")
self.assertEqual('bar', cursor.fetchone()[0])
incookie = Cookie()
incookie['trac_session'] = 'john'
req = Mock(authname='anonymous', base_path='/', incookie=incookie,
outcookie=Cookie())
session = Session(self.env, req)
self.assert_('foo' not in session)
session['foo'] = 'baz'
session.save()
cursor.execute("SELECT value FROM session_attribute "
"WHERE sid='john' AND authenticated=1 AND name='foo'")
rows = cursor.fetchall()
self.assertEqual(1, len(rows))
self.assertEqual('bar', rows[0][0])
cursor.execute("SELECT value FROM session_attribute "
"WHERE sid='john' AND authenticated=0 AND name='foo'")
rows = cursor.fetchall()
self.assertEqual(1, len(rows))
self.assertEqual('baz', rows[0][0])
示例5: test_delete_anonymous_session_var
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_delete_anonymous_session_var(self):
"""
Verify that modifying a variable updates the 'session' table accordingly
for an anonymous 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("bar", session["foo"])
del session["foo"]
session.save()
self.assertEqual(
0,
self.env.db_query(
"""
SELECT COUNT(*) FROM session_attribute
WHERE sid='123456' AND name='foo'
"""
)[0][0],
)
示例6: test_delete_empty_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_delete_empty_session(self):
"""
Verify that a session gets deleted when it doesn't have any data except
for the 'last_visit' timestamp.
"""
now = time.time()
# Make sure the session has data so that it doesn't get dropped
with self.env.db_transaction as db:
db("INSERT INTO session VALUES ('123456', 0, %s)",
(int(now - UPDATE_INTERVAL - 3600),))
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)
del session['foo']
session.save()
self.assertEqual(0, self.env.db_query("""
SELECT COUNT(*) FROM session WHERE sid='123456' AND authenticated=0
""")[0][0])
示例7: test_change_anonymous_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [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
"""))
示例8: test_authenticated_session_independence_var
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_authenticated_session_independence_var(self):
"""
Verify that an anonymous session with the same name as an authenticated
session doesn't interfere with the latter.
"""
with self.env.db_transaction as db:
db("INSERT INTO session VALUES ('john', 1, 0)")
db("INSERT INTO session_attribute VALUES ('john',1,'foo','bar')")
self.assertEqual('bar', self.env.db_query("""
SELECT value FROM session_attribute
WHERE sid='john' AND authenticated=1 AND name='foo'
""")[0][0])
incookie = Cookie()
incookie['trac_session'] = 'john'
req = Mock(authname='anonymous', base_path='/', incookie=incookie,
outcookie=Cookie())
session = Session(self.env, req)
self.assert_('foo' not in session)
session['foo'] = 'baz'
session.save()
rows = self.env.db_query("""
SELECT value FROM session_attribute
WHERE sid='john' AND authenticated=1 AND name='foo'
""")
self.assertEqual(1, len(rows))
self.assertEqual('bar', rows[0][0])
rows = self.env.db_query("""
SELECT value FROM session_attribute
WHERE sid='john' AND authenticated=0 AND name='foo'
""")
self.assertEqual(1, len(rows))
self.assertEqual('baz', rows[0][0])
示例9: test_update_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_update_session(self):
"""
Verify that accessing a session after one day updates the sessions
'last_visit' variable so that the session doesn't get purged.
"""
now = time.time()
# Make sure the session has data so that it doesn't get dropped
with self.env.db_transaction as db:
db("INSERT INTO session VALUES ('123456', 0, 1)")
db("""
INSERT INTO session_attribute
VALUES ('123456', 0, 'foo', 'bar')
""")
incookie = Cookie()
incookie['trac_session'] = '123456'
outcookie = Cookie()
req = Mock(authname='anonymous', base_path='/', incookie=incookie,
outcookie=outcookie)
session = Session(self.env, req)
session['modified'] = True
session.save() # updating does require modifications
self.assertEqual(PURGE_AGE, outcookie['trac_session']['expires'])
self.assertAlmostEqual(now, int(self.env.db_query("""
SELECT last_visit FROM session
WHERE sid='123456' AND authenticated=0
""")[0][0]), -1)
示例10: test_update_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_update_session(self):
"""
Verify that accessing a session after one day updates the sessions
'last_visit' variable so that the session doesn't get purged.
"""
now = time.time()
# Make sure the session has data so that it doesn't get dropped
cursor = self.db.cursor()
cursor.execute("INSERT INTO session VALUES ('123456', 0, 1)")
cursor.execute("INSERT INTO session_attribute VALUES "
"('123456', 0, 'foo', 'bar')")
incookie = Cookie()
incookie['trac_session'] = '123456'
outcookie = Cookie()
req = Mock(authname='anonymous', base_path='/', incookie=incookie,
outcookie=outcookie)
session = Session(self.env, req)
session.save() # updating should not require modifications
self.assertEqual(PURGE_AGE, outcookie['trac_session']['expires'])
cursor.execute("SELECT last_visit FROM session WHERE sid='123456' AND "
"authenticated=0")
self.assertAlmostEqual(now, int(cursor.fetchone()[0]), -1)
示例11: test_purge_anonymous_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_purge_anonymous_session(self):
"""
Verify that old sessions get purged.
"""
cursor = self.db.cursor()
cursor.execute("INSERT INTO session "
"VALUES ('123456', 0, %s)",
(0,))
cursor.execute("INSERT INTO session "
"VALUES ('987654', 0, %s)",
(int(time.time() - PURGE_AGE - 3600),))
cursor.execute("INSERT INTO session_attribute VALUES "
"('987654', 0, 'foo', 'bar')")
# We need to modify a different session to trigger the purging
incookie = Cookie()
incookie['trac_session'] = '123456'
req = Mock(authname='anonymous', base_path='/', incookie=incookie,
outcookie=Cookie())
session = Session(self.env, req)
session['foo'] = 'bar'
session.save()
cursor.execute("SELECT COUNT(*) FROM session WHERE sid='987654' AND "
"authenticated=0")
self.assertEqual(0, cursor.fetchone()[0])
示例12: _test_authenticated_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def _test_authenticated_session(self, username, fullname, email):
"""
Verifies that a session cookie does not get used if the user is logged
in, and that Trac expires the cookie.
"""
req = MockRequest(self.env, authname=username)
req.incookie['trac_session'] = '123456'
session = Session(self.env, req)
self.assertEqual(username, session.sid)
session['email'] = email
session['name'] = fullname
session.save()
示例13: test_add_authenticated_session_var
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_add_authenticated_session_var(self):
"""
Verify that new variables are inserted into the 'session' table in the
database for an authenticated session.
"""
req = Mock(authname='john', base_path='/', incookie=Cookie())
session = Session(self.env, req)
session['foo'] = 'bar'
session.save()
self.assertEqual('bar', self.env.db_query("""
SELECT value FROM session_attribute WHERE sid='john' AND name='foo'
""")[0][0])
示例14: test_add_anonymous_session_var
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_add_anonymous_session_var(self):
"""
Verify that new variables are inserted into the 'session' table in the
database for an anonymous session.
"""
incookie = Cookie()
incookie["trac_session"] = "123456"
req = Mock(authname="anonymous", base_path="/", incookie=incookie, outcookie=Cookie())
session = Session(self.env, req)
session["foo"] = "bar"
session.save()
self.assertEqual("bar", self.env.db_query("SELECT value FROM session_attribute WHERE sid='123456'")[0][0])
示例15: test_authenticated_session
# 需要导入模块: from trac.web.session import Session [as 别名]
# 或者: from trac.web.session.Session import save [as 别名]
def test_authenticated_session(self):
"""
Verifies that a session cookie does not get used if the user is logged
in, and that Trac expires the cookie.
"""
incookie = Cookie()
incookie["trac_session"] = "123456"
outcookie = Cookie()
req = Mock(authname="john", base_path="/", incookie=incookie, outcookie=outcookie)
session = Session(self.env, req)
self.assertEqual("john", session.sid)
session["foo"] = "bar"
session.save()
self.assertEquals(0, outcookie["trac_session"]["expires"])