Mercurial > hg > FileServer
annotate tests/test_directory_server.txt @ 34:aca8cb6bfd63 default tip
fix documentation + bump version
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Mon, 05 Mar 2012 14:09:43 -0800 |
| parents | d8b73d9b679d |
| children |
| rev | line source |
|---|---|
|
29
d8b73d9b679d
separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
1 Test Directory Server |
|
d8b73d9b679d
separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
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 |
|
7
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
11 Make a directory server:: |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
12 |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
13 >>> directory = os.path.join(here, 'example') |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
14 >>> os.path.exists(directory) and os.path.isdir(directory) |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
15 True |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
16 >>> app = fileserver.DirectoryServer(directory) |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
17 >>> testapp = TestApp(app) |
| 8 | 18 |
| 19 Ensure you can serve directory listings:: | |
| 20 | |
|
7
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
21 >>> response = testapp.get('/') |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
22 >>> response.status |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
23 200 |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
24 >>> 'helloworld.txt' in response.body |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
25 True |
| 8 | 26 |
| 27 Ensure you can serve file contents:: | |
| 28 | |
| 29 >>> response = testapp.get('/helloworld.txt') | |
| 30 >>> response.status | |
| 31 200 | |
|
29
d8b73d9b679d
separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
32 >>> filename = os.path.join(here, 'example', 'helloworld.txt') |
| 9 | 33 >>> response.body == file(filename).read() |
| 34 True | |
| 10 | 35 |
| 36 Ensure you get a 404 for nonexistent resources:: | |
| 37 | |
| 38 >>> response = testapp.get('/notfound.bin', status=404) | |
| 39 >>> response.status | |
| 40 404 | |
| 41 | |
|
15
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
42 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
|
43 |
|
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
44 >>> 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
|
45 >>> response.status |
|
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
46 404 |
|
21673816cfde
add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
47 |
| 11 | 48 Ensure you can get resources from subdirectories:: |
| 49 | |
| 50 >>> response = testapp.get('/foo') | |
| 12 | 51 >>> response.status # 301 Moved Permanently |
| 52 301 | |
| 53 >>> location = response.header_dict['location'] | |
| 54 >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location) | |
| 55 >>> path | |
| 56 '/foo/' | |
| 57 >>> response = testapp.get('/foo/') | |
| 11 | 58 >>> response.status |
| 12 | 59 200 |
| 60 >>> 'bar.txt' in response.body | |
| 61 True | |
|
14
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
62 >>> response = testapp.get('/foo/bar.txt') |
|
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
63 >>> response.status |
|
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
64 200 |
|
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
65 >>> 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
|
66 >>> response.body == file(filename).read() |
|
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
67 True |
| 11 | 68 |
| 69 Ensure you can't get to non-allowed resources:: | |
| 70 | |
| 17 | 71 >>> response = testapp.get('/../exampleBADBADBAD', status=404) |
|
14
c8520774ddc9
add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
72 >>> 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
|
73 404 |
|
18
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
74 >>> 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
|
75 >>> response.status |
|
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
76 301 |
|
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
77 >>> 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
|
78 >>> 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
|
79 >>> path |
|
76c939271534
introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
80 '/' |
