testing/mozbase/mozhttpd/tests/requestlog.py

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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/.
     5 import mozhttpd
     6 import urllib2
     7 import os
     8 import unittest
     9 import time
    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)
    22         data = f.read()
    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__':
    42     unittest.main()

mercurial