Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit 80f0a97

Browse files
committed
Improving functional test to assert no clashes between session and notifications
1 parent e79fc19 commit 80f0a97

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

tests/test_functional.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1+
import pickle
2+
13
from nose.tools import istest
24
import redis
35
from tornado.testing import AsyncHTTPTestCase
46
from tornado.web import Application, RequestHandler
57

68
from pycket.driver import RedisDriver
9+
from pycket.notification import NotificationMixin
710
from pycket.session import SessionMixin
811

912

1013
class FunctionalTest(AsyncHTTPTestCase):
11-
dataset = None
14+
session_dataset = None
15+
notification_dataset = None
1216

1317
def setUp(self):
1418
super(FunctionalTest, self).setUp()
15-
self.dataset.flushall()
19+
self.session_dataset.flushall()
20+
self.notification_dataset.flushall()
1621

1722
def get_app(self):
18-
if self.dataset is None:
19-
self.dataset = redis.Redis(db=RedisDriver.DEFAULT_STORAGE_IDENTIFIERS['db_sessions'])
23+
if self.session_dataset is None or self.notification_dataset is None:
24+
self.session_dataset = redis.Redis(db=RedisDriver.DEFAULT_STORAGE_IDENTIFIERS['db_sessions'])
25+
self.notification_dataset = redis.Redis(db=RedisDriver.DEFAULT_STORAGE_IDENTIFIERS['db_notifications'])
2026

21-
class SimpleHandler(RequestHandler, SessionMixin):
27+
class SimpleHandler(RequestHandler, SessionMixin, NotificationMixin):
2228
def get(self):
2329
self.session.set('foo', 'bar')
24-
self.write(self.session.get('foo'))
30+
self.notifications.set('foo', 'bar2')
31+
self.write('%s-%s' % (self.session.get('foo'), self.notifications.get('foo')))
2532

2633
def get_secure_cookie(self, *args, **kwargs):
2734
return 'some-generated-cookie'
@@ -32,16 +39,22 @@ def get_secure_cookie(self, *args, **kwargs):
3239
'cookie_secret': 'Python rocks!',
3340
'pycket': {
3441
'engine': 'redis',
42+
'storage': {
43+
'max_connections': 10,
44+
},
3545
}
3646
})
3747

3848
@istest
3949
def works_with_request_handlers(self):
40-
self.assertEqual(len(self.dataset.keys()), 0)
50+
self.assertEqual(len(self.session_dataset.keys()), 0)
4151

4252
response = self.fetch('/')
4353

4454
self.assertEqual(response.code, 200)
45-
self.assertIn('bar', str(response.body))
55+
self.assertIn('bar-bar2', str(response.body))
4656

47-
self.assertEqual(len(self.dataset.keys()), 1)
57+
session_data = pickle.loads(self.session_dataset['some-generated-cookie'])
58+
notification_data = pickle.loads(self.notification_dataset['some-generated-cookie'])
59+
self.assertEqual(session_data, {'foo': 'bar'})
60+
self.assertEqual(notification_data, {})

0 commit comments

Comments
 (0)