summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2011-01-10 11:57:59 -0800
committerAndy McCurdy <andy@andymccurdy.com>2011-01-10 11:57:59 -0800
commitf26de8ec0a2ae3dc97fc7be6ce65165a1fa17ca9 (patch)
tree80a2ac4aa2a2835e08f65676976b3103ce442a15 /tests
parent7112f5bc1115c099a4f7872b9088ce71b08f37ff (diff)
parentdfde2fc04868849f2a1db62bd29821810bd9168d (diff)
downloadredis-py-f26de8ec0a2ae3dc97fc7be6ce65165a1fa17ca9.tar.gz
Merge branch 'master' of https://github.com/wcmaier/redis-py into logging
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py3
-rw-r--r--tests/server_commands.py54
2 files changed, 56 insertions, 1 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
index 8931b07..63d6741 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,5 +1,5 @@
import unittest
-from server_commands import ServerCommandsTestCase
+from server_commands import ServerCommandsTestCase, LoggingTestCase
from connection_pool import ConnectionPoolTestCase
from pipeline import PipelineTestCase
from lock import LockTestCase
@@ -10,4 +10,5 @@ def all_tests():
suite.addTest(unittest.makeSuite(ConnectionPoolTestCase))
suite.addTest(unittest.makeSuite(PipelineTestCase))
suite.addTest(unittest.makeSuite(LockTestCase))
+ suite.addTest(unittest.makeSuite(LoggingTestCase))
return suite
diff --git a/tests/server_commands.py b/tests/server_commands.py
index 5cd63c5..f213321 100644
--- a/tests/server_commands.py
+++ b/tests/server_commands.py
@@ -3,6 +3,8 @@ import unittest
import datetime
import threading
import time
+import logging
+import logging.handlers
from distutils.version import StrictVersion
class ServerCommandsTestCase(unittest.TestCase):
@@ -1258,3 +1260,55 @@ class ServerCommandsTestCase(unittest.TestCase):
# check that it is possible to get list content by key name
for key in mapping.keys():
self.assertEqual(self.client.lrange(key, 0, -1), list(mapping[key]))
+
+class BufferingHandler(logging.handlers.BufferingHandler):
+
+ def __init__(self):
+ logging.handlers.BufferingHandler.__init__(self, None)
+
+ def shouldFlush(self, record):
+ return False
+
+class LoggingTestCase(unittest.TestCase):
+
+ def get_client(self):
+ return redis.Redis(host='localhost', port=6379, db=9)
+
+ def setUp(self):
+ self.client = self.get_client()
+ self.client.flushdb()
+
+ self.log = logging.getLogger("redis")
+ self.log.setLevel(logging.DEBUG)
+ self.handler = BufferingHandler()
+ self.log.addHandler(self.handler)
+ self.buffer = self.handler.buffer
+
+ def tearDown(self):
+ self.client.flushdb()
+ for c in self.client.connection_pool.get_all_connections():
+ c.disconnect()
+
+ def test_command_logging(self):
+ self.client.get("foo")
+
+ self.assertEqual(len(self.buffer), 1)
+ self.assertEqual(self.buffer[0].msg, "GET 'foo'")
+
+ def test_command_logging_pipeline(self):
+ pipe = self.client.pipeline(transaction=False)
+ pipe.get("foo")
+ pipe.execute()
+
+ self.assertEqual(len(self.buffer), 1)
+ self.assertEqual(self.buffer[0].msg, "PIPELINE> GET 'foo'")
+
+ def test_command_logging_transaction(self):
+ txn = self.client.pipeline(transaction=True)
+ txn.get("foo")
+ txn.execute()
+
+ self.assertEqual(len(self.buffer), 3)
+ messages = [x.msg for x in self.buffer]
+ self.assertEqual(messages,
+ ["MULTI", "TRANSACTION> GET 'foo'", "EXEC"])