annotate tests/doctest.txt @ 14:c8520774ddc9

add a test for reading subdirectory files
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 29 Feb 2012 15:45:27 -0800
parents 8127dde8da22
children 21673816cfde
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
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
11
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
54 Ensure you can get resources from subdirectories::
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
55
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
56 >>> response = testapp.get('/foo')
12
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
57 >>> response.status # 301 Moved Permanently
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
58 301
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
59 >>> location = response.header_dict['location']
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
60 >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location)
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
61 >>> path
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
62 '/foo/'
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
63 >>> response = testapp.get('/foo/')
11
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
64 >>> response.status
12
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
65 200
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
66 >>> 'bar.txt' in response.body
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
67 True
14
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
68 >>> response = testapp.get('/foo/bar.txt')
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
69 >>> response.status
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
70 200
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
71 >>> 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
72 >>> response.body == file(filename).read()
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
73 True
11
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
74
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
75 Ensure you can't get to non-allowed resources::
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
76
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
77 >>> response = testapp.get('/../exampleBADBADBAD')
14
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
78 >>> 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
79 404