testing/mozbase/mozhttpd/tests/filelisting.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python
michael@0 2
michael@0 3 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 # You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 6
michael@0 7 import mozhttpd
michael@0 8 import urllib2
michael@0 9 import os
michael@0 10 import unittest
michael@0 11 import re
michael@0 12
michael@0 13 here = os.path.dirname(os.path.abspath(__file__))
michael@0 14
michael@0 15 class FileListingTest(unittest.TestCase):
michael@0 16
michael@0 17 def check_filelisting(self, path=''):
michael@0 18 filelist = os.listdir(here)
michael@0 19
michael@0 20 httpd = mozhttpd.MozHttpd(port=0, docroot=here)
michael@0 21 httpd.start(block=False)
michael@0 22 f = urllib2.urlopen("http://%s:%s/%s" % ('127.0.0.1', httpd.httpd.server_port, path))
michael@0 23 for line in f.readlines():
michael@0 24 webline = re.sub('\<[a-zA-Z0-9\-\_\.\=\"\'\/\\\%\!\@\#\$\^\&\*\(\) ]*\>', '', line.strip('\n')).strip('/').strip().strip('@')
michael@0 25
michael@0 26 if webline and not webline.startswith("Directory listing for"):
michael@0 27 self.assertTrue(webline in filelist,
michael@0 28 "File %s in dir listing corresponds to a file" % webline)
michael@0 29 filelist.remove(webline)
michael@0 30 self.assertFalse(filelist, "Should have no items in filelist (%s) unaccounted for" % filelist)
michael@0 31
michael@0 32
michael@0 33 def test_filelist(self):
michael@0 34 self.check_filelisting()
michael@0 35
michael@0 36 def test_filelist_params(self):
michael@0 37 self.check_filelisting('?foo=bar&fleem=&foo=fleem')
michael@0 38
michael@0 39
michael@0 40 if __name__ == '__main__':
michael@0 41 unittest.main()

mercurial