# HG changeset patch # User Jeff Hammel # Date 1330982650 28800 # Node ID 4509330ef8ade40b307121b8940f16df6a5e3eed # Parent 41bd126ab77dce504ec725e34764e66aded39029 give a more appropriate name diff -r 41bd126ab77d -r 4509330ef8ad tests/doctest.txt --- a/tests/doctest.txt Mon Mar 05 13:23:05 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -Test FileServer -=============== - -The obligatory imports:: - - >>> import fileserver - >>> import os - >>> import urlparse - >>> from paste.fixture import TestApp - -Make a single file server:: - - >>> filename = os.path.join(here, 'example', 'helloworld.txt') - >>> os.path.exists(filename) - True - >>> app = fileserver.FileApp(filename) - >>> testapp = TestApp(app) - >>> response = testapp.get('/') - >>> response.status - 200 - >>> response.body == file(filename).read() - True - -Make a directory server:: - - >>> directory = os.path.join(here, 'example') - >>> os.path.exists(directory) and os.path.isdir(directory) - True - >>> app = fileserver.DirectoryServer(directory) - >>> testapp = TestApp(app) - -Ensure you can serve directory listings:: - - >>> response = testapp.get('/') - >>> response.status - 200 - >>> 'helloworld.txt' in response.body - True - -Ensure you can serve file contents:: - - >>> response = testapp.get('/helloworld.txt') - >>> response.status - 200 - >>> response.body == file(filename).read() - True - -Ensure you get a 404 for nonexistent resources:: - - >>> response = testapp.get('/notfound.bin', status=404) - >>> response.status - 404 - -Ensure we're not misusing slashes:: - - >>> response = testapp.get('/helloworld.txt/', status=404) - >>> response.status - 404 - -Ensure you can get resources from subdirectories:: - - >>> response = testapp.get('/foo') - >>> response.status # 301 Moved Permanently - 301 - >>> location = response.header_dict['location'] - >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location) - >>> path - '/foo/' - >>> response = testapp.get('/foo/') - >>> response.status - 200 - >>> 'bar.txt' in response.body - True - >>> response = testapp.get('/foo/bar.txt') - >>> response.status - 200 - >>> filename = os.path.join(here, 'example', 'foo', 'bar.txt') - >>> response.body == file(filename).read() - True - -Ensure you can't get to non-allowed resources:: - - >>> response = testapp.get('/../exampleBADBADBAD', status=404) - >>> response.status # Not Found: we do not want to give away these resources - 404 - >>> response = testapp.get('//') # XXX weird - >>> response.status - 301 - >>> location = response.header_dict['location'] - >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location) - >>> path - '/' diff -r 41bd126ab77d -r 4509330ef8ad tests/test_directory_server.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_directory_server.txt Mon Mar 05 13:24:10 2012 -0800 @@ -0,0 +1,92 @@ +Test FileServer +=============== + +The obligatory imports:: + + >>> import fileserver + >>> import os + >>> import urlparse + >>> from paste.fixture import TestApp + +Make a single file server:: + + >>> filename = os.path.join(here, 'example', 'helloworld.txt') + >>> os.path.exists(filename) + True + >>> app = fileserver.FileApp(filename) + >>> testapp = TestApp(app) + >>> response = testapp.get('/') + >>> response.status + 200 + >>> response.body == file(filename).read() + True + +Make a directory server:: + + >>> directory = os.path.join(here, 'example') + >>> os.path.exists(directory) and os.path.isdir(directory) + True + >>> app = fileserver.DirectoryServer(directory) + >>> testapp = TestApp(app) + +Ensure you can serve directory listings:: + + >>> response = testapp.get('/') + >>> response.status + 200 + >>> 'helloworld.txt' in response.body + True + +Ensure you can serve file contents:: + + >>> response = testapp.get('/helloworld.txt') + >>> response.status + 200 + >>> response.body == file(filename).read() + True + +Ensure you get a 404 for nonexistent resources:: + + >>> response = testapp.get('/notfound.bin', status=404) + >>> response.status + 404 + +Ensure we're not misusing slashes:: + + >>> response = testapp.get('/helloworld.txt/', status=404) + >>> response.status + 404 + +Ensure you can get resources from subdirectories:: + + >>> response = testapp.get('/foo') + >>> response.status # 301 Moved Permanently + 301 + >>> location = response.header_dict['location'] + >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location) + >>> path + '/foo/' + >>> response = testapp.get('/foo/') + >>> response.status + 200 + >>> 'bar.txt' in response.body + True + >>> response = testapp.get('/foo/bar.txt') + >>> response.status + 200 + >>> filename = os.path.join(here, 'example', 'foo', 'bar.txt') + >>> response.body == file(filename).read() + True + +Ensure you can't get to non-allowed resources:: + + >>> response = testapp.get('/../exampleBADBADBAD', status=404) + >>> response.status # Not Found: we do not want to give away these resources + 404 + >>> response = testapp.get('//') # XXX weird + >>> response.status + 301 + >>> location = response.header_dict['location'] + >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location) + >>> path + '/'