Skip to content
Browse files

Improving functional test to assert no clashes between session and no…

…tifications
  • Loading branch information...
1 parent e79fc19 commit 80f0a978d709f532698cc3ab6cb949d229c6c856 @diogobaeder committed Mar 11, 2013
Showing with 22 additions and 9 deletions.
  1. +22 −9 tests/test_functional.py
View
31 tests/test_functional.py
@@ -1,27 +1,34 @@
+import pickle
+
from nose.tools import istest
import redis
from tornado.testing import AsyncHTTPTestCase
from tornado.web import Application, RequestHandler
from pycket.driver import RedisDriver
+from pycket.notification import NotificationMixin
from pycket.session import SessionMixin
class FunctionalTest(AsyncHTTPTestCase):
- dataset = None
+ session_dataset = None
+ notification_dataset = None
def setUp(self):
super(FunctionalTest, self).setUp()
- self.dataset.flushall()
+ self.session_dataset.flushall()
+ self.notification_dataset.flushall()
def get_app(self):
- if self.dataset is None:
- self.dataset = redis.Redis(db=RedisDriver.DEFAULT_STORAGE_IDENTIFIERS['db_sessions'])
+ if self.session_dataset is None or self.notification_dataset is None:
+ self.session_dataset = redis.Redis(db=RedisDriver.DEFAULT_STORAGE_IDENTIFIERS['db_sessions'])
+ self.notification_dataset = redis.Redis(db=RedisDriver.DEFAULT_STORAGE_IDENTIFIERS['db_notifications'])
- class SimpleHandler(RequestHandler, SessionMixin):
+ class SimpleHandler(RequestHandler, SessionMixin, NotificationMixin):
def get(self):
self.session.set('foo', 'bar')
- self.write(self.session.get('foo'))
+ self.notifications.set('foo', 'bar2')
+ self.write('%s-%s' % (self.session.get('foo'), self.notifications.get('foo')))
def get_secure_cookie(self, *args, **kwargs):
return 'some-generated-cookie'
@@ -32,16 +39,22 @@ def get_secure_cookie(self, *args, **kwargs):
'cookie_secret': 'Python rocks!',
'pycket': {
'engine': 'redis',
+ 'storage': {
+ 'max_connections': 10,
+ },
}
})
@istest
def works_with_request_handlers(self):
- self.assertEqual(len(self.dataset.keys()), 0)
+ self.assertEqual(len(self.session_dataset.keys()), 0)
response = self.fetch('/')
self.assertEqual(response.code, 200)
- self.assertIn('bar', str(response.body))
+ self.assertIn('bar-bar2', str(response.body))
- self.assertEqual(len(self.dataset.keys()), 1)
+ session_data = pickle.loads(self.session_dataset['some-generated-cookie'])
+ notification_data = pickle.loads(self.notification_dataset['some-generated-cookie'])
+ self.assertEqual(session_data, {'foo': 'bar'})
+ self.assertEqual(notification_data, {})

0 comments on commit 80f0a97

Please sign in to comment.
Something went wrong with that request. Please try again.