summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2011-05-05 11:59:14 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2011-05-05 11:59:14 (GMT)
commit0372e106841e2d641556b6f5146d59cbe189534f (patch)
tree8305ae6560d213bbab352ebc343afa33fc81af8a /Lib/test
parent9cc432d93799652cb21ac4473d6875ed3de01937 (diff)
downloadcpython-0372e106841e2d641556b6f5146d59cbe189534f.zip
cpython-0372e106841e2d641556b6f5146d59cbe189534f.tar.gz
cpython-0372e106841e2d641556b6f5146d59cbe189534f.tar.bz2
Improved coverage and fixed bug in HTTPHandler with POST requests.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_logging.py42
1 files changed, 32 insertions, 10 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index bf0ad77..2e6de4c 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -1464,22 +1464,34 @@ class HTTPHandlerTest(BaseTest):
BaseTest.tearDown(self)
def handle_request(self, request):
+ self.command = request.command
self.log_data = urlparse(request.path)
+ if self.command == 'POST':
+ try:
+ rlen = int(request.headers['Content-Length'])
+ self.post_data = request.rfile.read(rlen)
+ except:
+ self.post_data = None
request.send_response(200)
self.handled.set()
def test_output(self):
# The log message sent to the SysLogHandler is properly received.
logger = logging.getLogger("http")
- msg = "sp\xe4m"
- logger.error(msg)
- self.handled.wait()
- self.assertEqual(self.log_data.path, '/frob')
- d = parse_qs(self.log_data.query)
- self.assertEqual(d['name'], ['http'])
- self.assertEqual(d['funcName'], ['test_output'])
- self.assertEqual(d['msg'], [msg])
-
+ for method in ('GET', 'POST'):
+ self.h_hdlr.method = method
+ msg = "sp\xe4m"
+ logger.error(msg)
+ self.handled.wait()
+ self.assertEqual(self.log_data.path, '/frob')
+ self.assertEqual(self.command, method)
+ if method == 'GET':
+ d = parse_qs(self.log_data.query)
+ else:
+ d = parse_qs(self.post_data.decode('utf-8'))
+ self.assertEqual(d['name'], ['http'])
+ self.assertEqual(d['funcName'], ['test_output'])
+ self.assertEqual(d['msg'], [msg])
class MemoryTest(BaseTest):
@@ -3470,7 +3482,8 @@ class RotatingFileHandlerTest(BaseFileTest):
class TimedRotatingFileHandlerTest(BaseFileTest):
# other test methods added below
def test_rollover(self):
- fh = logging.handlers.TimedRotatingFileHandler(self.fn, 'S')
+ fh = logging.handlers.TimedRotatingFileHandler(self.fn, 'S',
+ backupCount=1)
r = logging.makeLogRecord({'msg': 'testing'})
fh.emit(r)
self.assertLogFile(self.fn)
@@ -3481,6 +3494,15 @@ class TimedRotatingFileHandlerTest(BaseFileTest):
suffix = prevsec.strftime(".%Y-%m-%d_%H-%M-%S")
self.assertLogFile(self.fn + suffix)
+ def test_invalid(self):
+ assertRaises = self.assertRaises
+ assertRaises(ValueError, logging.handlers.TimedRotatingFileHandler,
+ self.fn, 'X')
+ assertRaises(ValueError, logging.handlers.TimedRotatingFileHandler,
+ self.fn, 'W')
+ assertRaises(ValueError, logging.handlers.TimedRotatingFileHandler,
+ self.fn, 'W7')
+
def secs(**kw):
return datetime.timedelta(**kw) // datetime.timedelta(seconds=1)