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