Mercurial > hg > FileServer
annotate tests/doctest.txt @ 10:1a11c096284b
som more tests
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 29 Feb 2012 15:04:03 -0800 |
parents | 68db1111f23a |
children | 1aaf2ba89b30 |
rev | line source |
---|---|
0 | 1 Test FileServer |
2 ================ | |
3 | |
6 | 4 The obligatory imports:: |
0 | 5 |
6 >>> import fileserver | |
6 | 7 >>> import os |
8 >>> from paste.fixture import TestApp | |
0 | 9 |
6 | 10 Make a single file server:: |
0 | 11 |
6 | 12 >>> filename = os.path.join(here, 'example', 'helloworld.txt') |
13 >>> os.path.exists(filename) | |
14 True | |
15 >>> app = fileserver.FileApp(filename) | |
16 >>> testapp = TestApp(app) | |
17 >>> response = testapp.get('/') | |
18 >>> response.status | |
19 200 | |
20 >>> response.body == file(filename).read() | |
21 True | |
7
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
22 |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
23 Make a directory server:: |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
24 |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
25 >>> directory = os.path.join(here, 'example') |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
26 >>> os.path.exists(directory) and os.path.isdir(directory) |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
27 True |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
28 >>> app = fileserver.DirectoryServer(directory) |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
29 >>> testapp = TestApp(app) |
8 | 30 |
31 Ensure you can serve directory listings:: | |
32 | |
7
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
33 >>> response = testapp.get('/') |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
34 >>> response.status |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
35 200 |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
36 >>> 'helloworld.txt' in response.body |
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
37 True |
8 | 38 |
39 Ensure you can serve file contents:: | |
40 | |
41 >>> response = testapp.get('/helloworld.txt') | |
42 >>> response.status | |
43 200 | |
9 | 44 >>> response.body == file(filename).read() |
45 True | |
10 | 46 |
47 Ensure you get a 404 for nonexistent resources:: | |
48 | |
49 >>> response = testapp.get('/notfound.bin', status=404) | |
50 >>> response.status | |
51 404 | |
52 |