本文整理汇总了Python中user_sessions.backends.db.SessionStore类的典型用法代码示例。如果您正苦于以下问题:Python SessionStore类的具体用法?Python SessionStore怎么用?Python SessionStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SessionStore类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_get_decoded
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})
开发者ID:tbeg,项目名称:django-user-sessions,代码行数:8,代码来源:tests.py
示例2: test_restore_session
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')
开发者ID:doselect,项目名称:django-user-sessions,代码行数:9,代码来源:tests.py
示例3: test_get_decoded
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})
开发者ID:doselect,项目名称:django-user-sessions,代码行数:9,代码来源:tests.py
示例4: test_load_modified
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)
开发者ID:doselect,项目名称:django-user-sessions,代码行数:9,代码来源:tests.py
示例5: test_restore_session
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")
开发者ID:tbeg,项目名称:django-user-sessions,代码行数:9,代码来源:tests.py
示例6: test_load_unmodified
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)
开发者ID:tbeg,项目名称:django-user-sessions,代码行数:9,代码来源:tests.py
示例7: test_very_long_ua
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])
开发者ID:doselect,项目名称:django-user-sessions,代码行数:10,代码来源:tests.py
示例8: test_load_unmodified
def test_load_unmodified(self):
self.store[auth.SESSION_KEY] = 1
self.store.save()
store2 = SessionStore(session_key=self.store.session_key,
user_agent='Python/2.7', ip='127.0.0.1')
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)
开发者ID:Bouke,项目名称:django-user-sessions,代码行数:10,代码来源:tests.py
示例9: test_duplicate_create
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)
开发者ID:doselect,项目名称:django-user-sessions,代码行数:10,代码来源:tests.py
示例10: setUp
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')
开发者ID:doselect,项目名称:django-user-sessions,代码行数:11,代码来源:tests.py
示例11: setUp
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")
开发者ID:tbeg,项目名称:django-user-sessions,代码行数:11,代码来源:tests.py
示例12: SessionStoreTest
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)
开发者ID:doselect,项目名称:django-user-sessions,代码行数:94,代码来源:tests.py
示例13: setUp
def setUp(self):
self.store = SessionStore(user_agent='Python/2.7', ip='127.0.0.1')
开发者ID:Bouke,项目名称:django-user-sessions,代码行数:2,代码来源:tests.py
注:本文中的user_sessions.backends.db.SessionStore类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论