1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozhttpd/tests/requestlog.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,42 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +import mozhttpd 1.9 +import urllib2 1.10 +import os 1.11 +import unittest 1.12 +import time 1.13 + 1.14 +here = os.path.dirname(os.path.abspath(__file__)) 1.15 + 1.16 +class RequestLogTest(unittest.TestCase): 1.17 + 1.18 + def check_logging(self, log_requests=False): 1.19 + filelist = os.listdir(here) 1.20 + 1.21 + httpd = mozhttpd.MozHttpd(port=0, docroot=here, log_requests=log_requests) 1.22 + httpd.start(block=False) 1.23 + url = "http://%s:%s/" % ('127.0.0.1', httpd.httpd.server_port) 1.24 + f = urllib2.urlopen(url) 1.25 + data = f.read() 1.26 + 1.27 + return httpd.request_log 1.28 + 1.29 + def test_logging_enabled(self): 1.30 + request_log = self.check_logging(log_requests=True) 1.31 + 1.32 + self.assertEqual(len(request_log), 1) 1.33 + 1.34 + log_entry = request_log[0] 1.35 + self.assertEqual(log_entry['method'], 'GET') 1.36 + self.assertEqual(log_entry['path'], '/') 1.37 + self.assertEqual(type(log_entry['time']), float) 1.38 + 1.39 + def test_logging_disabled(self): 1.40 + request_log = self.check_logging(log_requests=False) 1.41 + 1.42 + self.assertEqual(len(request_log), 0) 1.43 + 1.44 +if __name__ == '__main__': 1.45 + unittest.main()