diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2011-01-10 11:57:59 -0800 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2011-01-10 11:57:59 -0800 |
commit | f26de8ec0a2ae3dc97fc7be6ce65165a1fa17ca9 (patch) | |
tree | 80a2ac4aa2a2835e08f65676976b3103ce442a15 /tests/server_commands.py | |
parent | 7112f5bc1115c099a4f7872b9088ce71b08f37ff (diff) | |
parent | dfde2fc04868849f2a1db62bd29821810bd9168d (diff) | |
download | redis-py-f26de8ec0a2ae3dc97fc7be6ce65165a1fa17ca9.tar.gz |
Merge branch 'master' of https://github.com/wcmaier/redis-py into logging
Diffstat (limited to 'tests/server_commands.py')
-rw-r--r-- | tests/server_commands.py | 54 |
1 files changed, 54 insertions, 0 deletions
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"]) |