Mercurial > hg > FileServer
comparison tests/test_directory_server.txt @ 29:d8b73d9b679d
separate testing fileapp to its own doctest file
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 05 Mar 2012 13:27:06 -0800 |
parents | 4509330ef8ad |
children |
comparison
equal
deleted
inserted
replaced
28:4509330ef8ad | 29:d8b73d9b679d |
---|---|
1 Test FileServer | 1 Test Directory Server |
2 =============== | 2 ===================== |
3 | 3 |
4 The obligatory imports:: | 4 The obligatory imports:: |
5 | 5 |
6 >>> import fileserver | 6 >>> import fileserver |
7 >>> import os | 7 >>> import os |
8 >>> import urlparse | 8 >>> import urlparse |
9 >>> from paste.fixture import TestApp | 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 | 10 |
24 Make a directory server:: | 11 Make a directory server:: |
25 | 12 |
26 >>> directory = os.path.join(here, 'example') | 13 >>> directory = os.path.join(here, 'example') |
27 >>> os.path.exists(directory) and os.path.isdir(directory) | 14 >>> os.path.exists(directory) and os.path.isdir(directory) |
40 Ensure you can serve file contents:: | 27 Ensure you can serve file contents:: |
41 | 28 |
42 >>> response = testapp.get('/helloworld.txt') | 29 >>> response = testapp.get('/helloworld.txt') |
43 >>> response.status | 30 >>> response.status |
44 200 | 31 200 |
32 >>> filename = os.path.join(here, 'example', 'helloworld.txt') | |
45 >>> response.body == file(filename).read() | 33 >>> response.body == file(filename).read() |
46 True | 34 True |
47 | 35 |
48 Ensure you get a 404 for nonexistent resources:: | 36 Ensure you get a 404 for nonexistent resources:: |
49 | 37 |