comparison tests/test_directory_server.txt @ 28:4509330ef8ad

give a more appropriate name
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 05 Mar 2012 13:24:10 -0800
parents tests/doctest.txt@76c939271534
children d8b73d9b679d
comparison
equal deleted inserted replaced
27:41bd126ab77d 28:4509330ef8ad
1 Test FileServer
2 ===============
3
4 The obligatory imports::
5
6 >>> import fileserver
7 >>> import os
8 >>> import urlparse
9 >>> from paste.fixture import TestApp
10
11 Make a single file server::
12
13 >>> filename = os.path.join(here, 'example', 'helloworld.txt')
14 >>> os.path.exists(filename)
15 True
16 >>> app = fileserver.FileApp(filename)
17 >>> testapp = TestApp(app)
18 >>> response = testapp.get('/')
19 >>> response.status
20 200
21 >>> response.body == file(filename).read()
22 True
23
24 Make a directory server::
25
26 >>> directory = os.path.join(here, 'example')
27 >>> os.path.exists(directory) and os.path.isdir(directory)
28 True
29 >>> app = fileserver.DirectoryServer(directory)
30 >>> testapp = TestApp(app)
31
32 Ensure you can serve directory listings::
33
34 >>> response = testapp.get('/')
35 >>> response.status
36 200
37 >>> 'helloworld.txt' in response.body
38 True
39
40 Ensure you can serve file contents::
41
42 >>> response = testapp.get('/helloworld.txt')
43 >>> response.status
44 200
45 >>> response.body == file(filename).read()
46 True
47
48 Ensure you get a 404 for nonexistent resources::
49
50 >>> response = testapp.get('/notfound.bin', status=404)
51 >>> response.status
52 404
53
54 Ensure we're not misusing slashes::
55
56 >>> response = testapp.get('/helloworld.txt/', status=404)
57 >>> response.status
58 404
59
60 Ensure you can get resources from subdirectories::
61
62 >>> response = testapp.get('/foo')
63 >>> response.status # 301 Moved Permanently
64 301
65 >>> location = response.header_dict['location']
66 >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location)
67 >>> path
68 '/foo/'
69 >>> response = testapp.get('/foo/')
70 >>> response.status
71 200
72 >>> 'bar.txt' in response.body
73 True
74 >>> response = testapp.get('/foo/bar.txt')
75 >>> response.status
76 200
77 >>> filename = os.path.join(here, 'example', 'foo', 'bar.txt')
78 >>> response.body == file(filename).read()
79 True
80
81 Ensure you can't get to non-allowed resources::
82
83 >>> response = testapp.get('/../exampleBADBADBAD', status=404)
84 >>> response.status # Not Found: we do not want to give away these resources
85 404
86 >>> response = testapp.get('//') # XXX weird
87 >>> response.status
88 301
89 >>> location = response.header_dict['location']
90 >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location)
91 >>> path
92 '/'