本文整理汇总了Python中user_sessions.backends.db.SessionStore.delete方法的典型用法代码示例。如果您正苦于以下问题:Python SessionStore.delete方法的具体用法?Python SessionStore.delete怎么用?Python SessionStore.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user_sessions.backends.db.SessionStore
的用法示例。
在下文中一共展示了SessionStore.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SessionStoreTest
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import delete [as 别名]
class SessionStoreTest(TestCase):
def setUp(self):
self.store = SessionStore('Python/2.7', '127.0.0.1', None)
def test_untouched_init(self):
self.assertFalse(self.store.modified)
self.assertFalse(self.store.accessed)
def test_auth_session_key(self):
self.assertFalse(auth.SESSION_KEY in self.store)
self.assertFalse(self.store.modified)
self.assertTrue(self.store.accessed)
self.store.get(auth.SESSION_KEY)
self.assertFalse(self.store.modified)
self.store[auth.SESSION_KEY] = 1
self.assertTrue(self.store.modified)
def test_save(self):
self.store[auth.SESSION_KEY] = 1
self.store.save()
session = Session.objects.get(pk=self.store.session_key)
self.assertEqual(session.user_agent, 'Python/2.7')
self.assertEqual(session.ip, '127.0.0.1')
self.assertEqual(session.user_id, 1)
self.assertAlmostEqual(now(), session.last_activity,
delta=timedelta(seconds=5))
def test_load_unmodified(self):
self.store[auth.SESSION_KEY] = 1
self.store.save()
store2 = SessionStore('Python/2.7', '127.0.0.1',
self.store.session_key)
store2.load()
self.assertEqual(store2.user_agent, 'Python/2.7')
self.assertEqual(store2.ip, '127.0.0.1')
self.assertEqual(store2.user_id, 1)
self.assertEqual(store2.modified, False)
def test_load_modified(self):
self.store[auth.SESSION_KEY] = 1
self.store.save()
store2 = SessionStore('Python/3.3', '8.8.8.8', self.store.session_key)
store2.load()
self.assertEqual(store2.user_agent, 'Python/3.3')
self.assertEqual(store2.ip, '8.8.8.8')
self.assertEqual(store2.user_id, 1)
self.assertEqual(store2.modified, True)
def test_duplicate_create(self):
s1 = SessionStore('Python/2.7', '127.0.0.1', 'DUPLICATE')
s1.create()
s2 = SessionStore('Python/2.7', '127.0.0.1', 'DUPLICATE')
s2.create()
self.assertNotEqual(s1.session_key, s2.session_key)
s3 = SessionStore('Python/2.7', '127.0.0.1', s1.session_key)
with self.assertRaises(CreateError):
s3.save(must_create=True)
def test_integrity(self):
self.store.user_agent = None
with self.assertRaisesRegexp(
IntegrityError,
'(user_sessions_session.user_agent may not be NULL|'
'NOT NULL constraint failed: user_sessions_session.user_agent)'
):
self.store.save()
def test_delete(self):
# not persisted, should just return
self.store.delete()
# create, then delete
self.store.create()
session_key = self.store.session_key
self.store.delete()
# non-existing sessions, should not raise
self.store.delete()
self.store.delete(session_key)
def test_clear(self):
"""
Clearing the session should clear all non-browser information
"""
self.store[auth.SESSION_KEY] = 1
self.store.clear()
self.store.save()
session = Session.objects.get(pk=self.store.session_key)
self.assertEqual(session.user_id, None)