michael@0: #!/usr/bin/env python michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import mozhttpd michael@0: import urllib2 michael@0: import os michael@0: import unittest michael@0: import re michael@0: michael@0: here = os.path.dirname(os.path.abspath(__file__)) michael@0: michael@0: class FileListingTest(unittest.TestCase): michael@0: michael@0: def check_filelisting(self, path=''): michael@0: filelist = os.listdir(here) michael@0: michael@0: httpd = mozhttpd.MozHttpd(port=0, docroot=here) michael@0: httpd.start(block=False) michael@0: f = urllib2.urlopen("http://%s:%s/%s" % ('127.0.0.1', httpd.httpd.server_port, path)) michael@0: for line in f.readlines(): michael@0: webline = re.sub('\<[a-zA-Z0-9\-\_\.\=\"\'\/\\\%\!\@\#\$\^\&\*\(\) ]*\>', '', line.strip('\n')).strip('/').strip().strip('@') michael@0: michael@0: if webline and not webline.startswith("Directory listing for"): michael@0: self.assertTrue(webline in filelist, michael@0: "File %s in dir listing corresponds to a file" % webline) michael@0: filelist.remove(webline) michael@0: self.assertFalse(filelist, "Should have no items in filelist (%s) unaccounted for" % filelist) michael@0: michael@0: michael@0: def test_filelist(self): michael@0: self.check_filelisting() michael@0: michael@0: def test_filelist_params(self): michael@0: self.check_filelisting('?foo=bar&fleem=&foo=fleem') michael@0: michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()