annotate tests/test_directory_server.txt @ 34:aca8cb6bfd63 default tip

fix documentation + bump version
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 05 Mar 2012 14:09:43 -0800
parents d8b73d9b679d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
1 Test Directory Server
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents: 28
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
7
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
11 Make a directory server::
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
12
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
13 >>> directory = os.path.join(here, 'example')
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
14 >>> os.path.exists(directory) and os.path.isdir(directory)
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
15 True
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
16 >>> app = fileserver.DirectoryServer(directory)
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
17 >>> testapp = TestApp(app)
8
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
18
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
19 Ensure you can serve directory listings::
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
20
7
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
21 >>> response = testapp.get('/')
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
22 >>> response.status
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
23 200
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
24 >>> 'helloworld.txt' in response.body
4d1852cfc077 rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents: 6
diff changeset
25 True
8
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
26
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
27 Ensure you can serve file contents::
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
28
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
29 >>> response = testapp.get('/helloworld.txt')
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
30 >>> response.status
782e15b86b86 serve file contents
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
31 200
29
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents: 28
diff changeset
32 >>> filename = os.path.join(here, 'example', 'helloworld.txt')
9
68db1111f23a serve file contents, pt 2
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
33 >>> response.body == file(filename).read()
68db1111f23a serve file contents, pt 2
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
34 True
10
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
35
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
36 Ensure you get a 404 for nonexistent resources::
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
37
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
38 >>> response = testapp.get('/notfound.bin', status=404)
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
39 >>> response.status
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
40 404
1a11c096284b som more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
41
15
21673816cfde add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
42 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
43
21673816cfde add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
44 >>> 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
45 >>> response.status
21673816cfde add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
46 404
21673816cfde add a test for normal files ending with slashes
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
47
11
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
48 Ensure you can get resources from subdirectories::
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
49
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
50 >>> response = testapp.get('/foo')
12
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
51 >>> response.status # 301 Moved Permanently
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
52 301
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
53 >>> location = response.header_dict['location']
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
54 >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location)
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
55 >>> path
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
56 '/foo/'
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
57 >>> response = testapp.get('/foo/')
11
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
58 >>> response.status
12
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
59 200
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
60 >>> 'bar.txt' in response.body
8127dde8da22 fix slashing
Jeff Hammel <jhammel@mozilla.com>
parents: 11
diff changeset
61 True
14
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
62 >>> response = testapp.get('/foo/bar.txt')
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
63 >>> response.status
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
64 200
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
65 >>> 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
66 >>> response.body == file(filename).read()
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
67 True
11
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
68
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
69 Ensure you can't get to non-allowed resources::
1aaf2ba89b30 introduce failing tests
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
70
17
27bd18f0a359 fix up security hole
Jeff Hammel <jhammel@mozilla.com>
parents: 16
diff changeset
71 >>> response = testapp.get('/../exampleBADBADBAD', status=404)
14
c8520774ddc9 add a test for reading subdirectory files
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
72 >>> 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
73 404
18
76c939271534 introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
74 >>> 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
75 >>> response.status
76c939271534 introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
76 301
76c939271534 introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
77 >>> 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
78 >>> 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
79 >>> path
76c939271534 introduce a test that i dont know what it means
Jeff Hammel <jhammel@mozilla.com>
parents: 17
diff changeset
80 '/'