testing/mozbase/mozhttpd/tests/requestlog.py

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:3dd3bea57ea1
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 import mozhttpd
6 import urllib2
7 import os
8 import unittest
9 import time
10
11 here = os.path.dirname(os.path.abspath(__file__))
12
13 class RequestLogTest(unittest.TestCase):
14
15 def check_logging(self, log_requests=False):
16 filelist = os.listdir(here)
17
18 httpd = mozhttpd.MozHttpd(port=0, docroot=here, log_requests=log_requests)
19 httpd.start(block=False)
20 url = "http://%s:%s/" % ('127.0.0.1', httpd.httpd.server_port)
21 f = urllib2.urlopen(url)
22 data = f.read()
23
24 return httpd.request_log
25
26 def test_logging_enabled(self):
27 request_log = self.check_logging(log_requests=True)
28
29 self.assertEqual(len(request_log), 1)
30
31 log_entry = request_log[0]
32 self.assertEqual(log_entry['method'], 'GET')
33 self.assertEqual(log_entry['path'], '/')
34 self.assertEqual(type(log_entry['time']), float)
35
36 def test_logging_disabled(self):
37 request_log = self.check_logging(log_requests=False)
38
39 self.assertEqual(len(request_log), 0)
40
41 if __name__ == '__main__':
42 unittest.main()

mercurial