Mercurial > hg > FileServer
annotate tests/doctest.txt @ 13:e3993fa05b89
cleanup
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 29 Feb 2012 15:42:14 -0800 |
parents | 8127dde8da22 |
children | c8520774ddc9 |
rev | line source |
---|---|
0 | 1 Test FileServer |
2 ================ | |
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 | |
11 | 54 Ensure you can get resources from subdirectories:: |
55 | |
56 >>> response = testapp.get('/foo') | |
12 | 57 >>> response.status # 301 Moved Permanently |
58 301 | |
59 >>> location = response.header_dict['location'] | |
60 >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location) | |
61 >>> path | |
62 '/foo/' | |
63 >>> response = testapp.get('/foo/') | |
11 | 64 >>> response.status |
12 | 65 200 |
66 >>> 'bar.txt' in response.body | |
67 True | |
11 | 68 |
69 Ensure you can't get to non-allowed resources:: | |
70 | |
71 >>> response = testapp.get('/../exampleBADBADBAD') |