本文整理汇总了Python中user_sessions.backends.db.SessionStore.save方法的典型用法代码示例。如果您正苦于以下问题:Python SessionStore.save方法的具体用法?Python SessionStore.save怎么用?Python SessionStore.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user_sessions.backends.db.SessionStore
的用法示例。
在下文中一共展示了SessionStore.save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_decoded
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import save [as 别名]
def test_get_decoded(self):
store = SessionStore("Python/2.7", "127.0.0.1", None)
store[auth.SESSION_KEY] = 1
store["foo"] = "bar"
store.save()
session = Session.objects.get(pk=store.session_key)
self.assertEqual(session.get_decoded(), {"foo": "bar", auth.SESSION_KEY: 1})
示例2: test_restore_session
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import save [as 别名]
def test_restore_session(self):
store = SessionStore('Python/2.7', '127.0.0.1', None)
store['foo'] = 'bar'
store.save()
client = Client()
client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
User.objects.create_user('bouke', '', 'secret')
assert client.login(username='bouke', password='secret')
self.assertEqual(client.session['foo'], 'bar')
示例3: test_get_decoded
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import save [as 别名]
def test_get_decoded(self):
store = SessionStore('Python/2.7', '127.0.0.1', None)
store[auth.SESSION_KEY] = 1
store['foo'] = 'bar'
store.save()
session = Session.objects.get(pk=store.session_key)
self.assertEqual(session.get_decoded(),
{'foo': 'bar', auth.SESSION_KEY: 1})
示例4: test_restore_session
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import save [as 别名]
def test_restore_session(self):
store = SessionStore("Python/2.7", "127.0.0.1", None)
store["foo"] = "bar"
store.save()
client = Client()
client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
User.objects.create_user("bouke", "", "secret")
assert client.login(username="bouke", password="secret")
self.assertEqual(client.session["foo"], "bar")
示例5: test_very_long_ua
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import save [as 别名]
def test_very_long_ua(self):
ua = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; ' \
'Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; ' \
'.NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; ' \
'InfoPath.3; ms-office; MSOffice 14)'
store = SessionStore(ua, '127.0.0.1', None)
store.save()
session = Session.objects.get(pk=store.session_key)
self.assertEqual(session.user_agent, ua[:200])
示例6: test_duplicate_create
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import save [as 别名]
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)
示例7: setUp
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import save [as 别名]
def setUp(self):
User.objects.create_superuser('bouke', '', 'secret')
assert self.client.login(username='bouke', password='secret')
expired = SessionStore('Python/2.5', '20.13.1.1')
expired.set_expiry(-365 * 86400)
expired.save()
unexpired = SessionStore('Python/2.7', '1.1.1.1')
unexpired.save()
self.admin_url = reverse('admin:user_sessions_session_changelist')
示例8: setUp
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import save [as 别名]
def setUp(self):
User.objects.create_superuser("bouke", "", "secret")
assert self.client.login(username="bouke", password="secret")
expired = SessionStore("Python/2.5", "20.13.1.1")
expired.set_expiry(-365 * 86400)
expired.save()
unexpired = SessionStore("Python/2.7", "1.1.1.1")
unexpired.save()
self.admin_url = reverse("admin:user_sessions_session_changelist")
示例9: SessionStoreTest
# 需要导入模块: from user_sessions.backends.db import SessionStore [as 别名]
# 或者: from user_sessions.backends.db.SessionStore import save [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)