This repository was archived by the owner on Jul 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtest_functional.py
More file actions
60 lines (47 loc) · 2.06 KB
/
test_functional.py
File metadata and controls
60 lines (47 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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):
session_dataset = None
notification_dataset = None
def setUp(self):
super(FunctionalTest, self).setUp()
self.session_dataset.flushall()
self.notification_dataset.flushall()
def get_app(self):
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, NotificationMixin):
def get(self):
self.session.set('foo', 'bar')
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'
return Application([
(r'/', SimpleHandler),
], **{
'cookie_secret': 'Python rocks!',
'pycket': {
'engine': 'redis',
'storage': {
'max_connections': 10,
},
}
})
@istest
def works_with_request_handlers(self):
self.assertEqual(len(self.session_dataset.keys()), 0)
response = self.fetch('/')
self.assertEqual(response.code, 200)
self.assertIn('bar-bar2', str(response.body))
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, {})