Mercurial > hg > FileServer
annotate tests/doctest.txt @ 19:c6e459be8534
fix install script
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 29 Feb 2012 16:15:31 -0800 |
parents | 76c939271534 |
children |
rev | line source |
---|---|
0 | 1 Test FileServer |
16 | 2 =============== |
0 | 3 |
6 | 4 The obligatory imports:: |
0 | 5 |
6 >>> import fileserver | |
6 | 7 >>> import os |
12 | 8 >>> import urlparse |
6 | 9 >>> from paste.fixture import TestApp |
0 | 10 |
6 | 11 Make a single file server:: |
0 | 12 |
6 | 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 | |
7
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
23 |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
24 Make a directory server:: |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
25 |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
26 >>> directory = os.path.join(here, 'example') |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
27 >>> os.path.exists(directory) and os.path.isdir(directory) |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
28 True |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
29 >>> app = fileserver.DirectoryServer(directory) |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
30 >>> testapp = TestApp(app) |
8 | 31 |
32 Ensure you can serve directory listings:: | |
33 | |
7
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
34 >>> response = testapp.get('/') |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
35 >>> response.status |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
36 200 |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
37 >>> 'helloworld.txt' in response.body |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
38 True |
8 | 39 |
40 Ensure you can serve file contents:: | |
41 | |
42 >>> response = testapp.get('/helloworld.txt') | |
43 >>> response.status | |
44 200 | |
9 | 45 >>> response.body == file(filename).read() |
46 True | |
10 | 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 | |
15
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
54 Ensure we're not misusing slashes:: |
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
55 |
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
56 >>> response = testapp.get('/helloworld.txt/', status=404) |
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
57 >>> response.status |
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
58 404 |
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
59 |
11 | 60 Ensure you can get resources from subdirectories:: |
61 | |
62 >>> response = testapp.get('/foo') | |
12 | 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/') | |
11 | 70 >>> response.status |
12 | 71 200 |
72 >>> 'bar.txt' in response.body | |
73 True | |
14
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
74 >>> response = testapp.get('/foo/bar.txt') |
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
75 >>> response.status |
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
76 200 |
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
77 >>> filename = os.path.join(here, 'example', 'foo', 'bar.txt') |
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
78 >>> response.body == file(filename).read() |
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
79 True |
11 | 80 |
81 Ensure you can't get to non-allowed resources:: | |
82 | |
17 | 83 >>> response = testapp.get('/../exampleBADBADBAD', status=404) |
14
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
84 >>> response.status # Not Found: we do not want to give away these resources |
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
85 404 |
18
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
86 >>> response = testapp.get('//') # XXX weird |
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
87 >>> response.status |
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
88 301 |
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
89 >>> location = response.header_dict['location'] |
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
90 >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location) |
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
91 >>> path |
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
92 '/' |