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