annotate tests/doctest.txt @ 26:395c6744bcd9

upgrading with suggestions from http://docs.webob.org/en/latest/file-example.html
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 05 Mar 2012 13:15:45 -0800
parents 76c939271534
children
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
16
4f26df21dc12 spacing
Jeff Hammel <jhammel@mozilla.com>
parents: 15
diff changeset
2 ===============
0
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
12
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
8 >>> import urlparse
6
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
9 >>> from paste.fixture import TestApp
0
8d31e36f084e initial stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
6
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
11 Make a single file server::
0
8d31e36f084e initial stubbing
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12
6
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
13 >>> filename = os.path.join(here, 'example', 'helloworld.txt')
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
14 >>> os.path.exists(filename)
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
15 True
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
16 >>> app = fileserver.FileApp(filename)
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
17 >>> testapp = TestApp(app)
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
18 >>> response = testapp.get('/')
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
19 >>> response.status
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
20 200
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
21 >>> response.body == file(filename).read()
623358c3ebde we has a passing test!
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
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
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
31
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
32 Ensure you can serve directory listings::
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
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
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
39
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
40 Ensure you can serve file contents::
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
41
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
42 >>> response = testapp.get('/helloworld.txt')
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
43 >>> response.status
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
44 200
9
68db1111f23a serve file contents, pt 2
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
45 >>> response.body == file(filename).read()
68db1111f23a serve file contents, pt 2
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
46 True
10
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
47
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
48 Ensure you get a 404 for nonexistent resources::
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
49
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
50 >>> response = testapp.get('/notfound.bin', status=404)
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
51 >>> response.status
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
52 404
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
53
15
21673816cfde add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
54 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
55
21673816cfde add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
56 >>> 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
57 >>> response.status
21673816cfde add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
58 404
21673816cfde add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
59
11
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
60 Ensure you can get resources from subdirectories::
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
61
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
62 >>> response = testapp.get('/foo')
12
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
63 >>> response.status # 301 Moved Permanently
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
64 301
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
65 >>> location = response.header_dict['location']
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
66 >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location)
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
67 >>> path
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
68 '/foo/'
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
69 >>> response = testapp.get('/foo/')
11
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
70 >>> response.status
12
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
71 200
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
72 >>> 'bar.txt' in response.body
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
73 True
14
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
74 >>> response = testapp.get('/foo/bar.txt')
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
75 >>> response.status
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
76 200
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
77 >>> 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
78 >>> response.body == file(filename).read()
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
79 True
11
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
80
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
81 Ensure you can't get to non-allowed resources::
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
82
17
27bd18f0a359 fix up security hole
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
83 >>> response = testapp.get('/../exampleBADBADBAD', status=404)
14
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
84 >>> 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
85 404
18
76c939271534 introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
86 >>> 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
87 >>> response.status
76c939271534 introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
88 301
76c939271534 introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
89 >>> 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
90 >>> 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
91 >>> path
76c939271534 introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
92 '/'