annotate tests/doctest.txt @ 8:782e15b86b86

serve file contents
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 29 Feb 2012 14:51:00 -0800
parents 4d1852cfc077
children 68db1111f23a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8d31e36f084e initial stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 Test FileServer
8d31e36f084e initial stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 ================
8d31e36f084e initial stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
6
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
4 The obligatory imports::
0
8d31e36f084e initial stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
8d31e36f084e initial stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 >>> import fileserver
6
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
7 >>> import os
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
8 >>> from paste.fixture import TestApp
0
8d31e36f084e initial stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9
6
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
10 Make a single file server::
0
8d31e36f084e initial stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
6
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
12 >>> filename = os.path.join(here, 'example', 'helloworld.txt')
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
13 >>> os.path.exists(filename)
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
14 True
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
15 >>> app = fileserver.FileApp(filename)
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
16 >>> testapp = TestApp(app)
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
17 >>> response = testapp.get('/')
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
18 >>> response.status
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
19 200
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
20 >>> response.body == file(filename).read()
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
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
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
30
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
31 Ensure you can serve directory listings::
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
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
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
38
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
39 Ensure you can serve file contents::
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
40
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
41 >>> response = testapp.get('/helloworld.txt')
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
42 >>> response.status
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
43 200