1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozhttpd/tests/filelisting.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,41 @@ 1.4 +#!/usr/bin/env python 1.5 + 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 + 1.10 +import mozhttpd 1.11 +import urllib2 1.12 +import os 1.13 +import unittest 1.14 +import re 1.15 + 1.16 +here = os.path.dirname(os.path.abspath(__file__)) 1.17 + 1.18 +class FileListingTest(unittest.TestCase): 1.19 + 1.20 + def check_filelisting(self, path=''): 1.21 + filelist = os.listdir(here) 1.22 + 1.23 + httpd = mozhttpd.MozHttpd(port=0, docroot=here) 1.24 + httpd.start(block=False) 1.25 + f = urllib2.urlopen("http://%s:%s/%s" % ('127.0.0.1', httpd.httpd.server_port, path)) 1.26 + for line in f.readlines(): 1.27 + webline = re.sub('\<[a-zA-Z0-9\-\_\.\=\"\'\/\\\%\!\@\#\$\^\&\*\(\) ]*\>', '', line.strip('\n')).strip('/').strip().strip('@') 1.28 + 1.29 + if webline and not webline.startswith("Directory listing for"): 1.30 + self.assertTrue(webline in filelist, 1.31 + "File %s in dir listing corresponds to a file" % webline) 1.32 + filelist.remove(webline) 1.33 + self.assertFalse(filelist, "Should have no items in filelist (%s) unaccounted for" % filelist) 1.34 + 1.35 + 1.36 + def test_filelist(self): 1.37 + self.check_filelisting() 1.38 + 1.39 + def test_filelist_params(self): 1.40 + self.check_filelisting('?foo=bar&fleem=&foo=fleem') 1.41 + 1.42 + 1.43 +if __name__ == '__main__': 1.44 + unittest.main()