def gets_default_value_if_provided_and_not_in_client(self): handler = StubHandler() manager = NotificationManager(handler) value = manager.get('foo', 'Default') self.assertEqual(value, 'Default')
def gets_a_notification_only_once(self): handler = StubHandler() manager = NotificationManager(handler) manager.set('foo', 'bar') self.assertEqual(manager.get('foo'), 'bar') self.assertIsNone(manager.get('foo'))
def uses_custom_notifications_database_if_provided(self): handler = StubHandler() handler.settings = { 'pycket': { 'engine': 'redis', 'storage': { 'db_sessions': 10, 'db_notifications': 11, } } } manager = NotificationManager(handler) manager.set('foo', 'bar') self.assertEqual(manager.driver.client.connection_pool._available_connections[0].db, 11)
def uses_custom_notifications_database_if_provided(self): handler = StubHandler() handler.settings = { 'pycket': { 'engine': 'redis', 'storage': { 'db_sessions': 10, 'db_notifications': 11, } } } manager = NotificationManager(handler) manager.set('foo', 'bar') self.assertEqual( manager.driver.client.connection_pool._available_connections[0].db, 11)
def sets_object_with_dict_key(self): handler = StubHandler() manager = NotificationManager(handler) manager['foo'] = 'bar' self.assertEqual(manager['foo'], 'bar')
def removes_notification_from_database_after_retrieval(self): handler = StubHandler() manager = NotificationManager(handler) manager.set('foo', 'bar') raw_notifications = self.client.get(handler.session_id) notifications = pickle.loads(raw_notifications) self.assertEqual(list(notifications.keys()), ['foo']) manager.get('foo') raw_notifications = self.client.get(handler.session_id) notifications = pickle.loads(raw_notifications) self.assertEqual(list(notifications.keys()), [])