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/.
11
here = os.path.dirname(os.path.abspath(__file__))
13
class RequestLogTest(unittest.TestCase):
15
def check_logging(self, log_requests=False):
16
filelist = os.listdir(here)
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)
24
return httpd.request_log
26
def test_logging_enabled(self):
27
request_log = self.check_logging(log_requests=True)
29
self.assertEqual(len(request_log), 1)
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)
36
def test_logging_disabled(self):
37
request_log = self.check_logging(log_requests=False)
39
self.assertEqual(len(request_log), 0)
41
if __name__ == '__main__':