annotate tests/test_fileapp.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 86b519dd8467
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:
diff changeset
1 Test FileApp
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 ============
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 The obligatory imports::
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 >>> import fileserver
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 >>> import os
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 >>> from paste.fixture import TestApp
30
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
9 >>> from webob import Request
29
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 Make a single file server::
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 >>> filename = os.path.join(here, 'example', 'helloworld.txt')
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 >>> os.path.exists(filename)
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 True
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 >>> app = fileserver.FileApp(filename)
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 >>> testapp = TestApp(app)
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 >>> response = testapp.get('/')
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 >>> response.status
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 200
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 >>> response.body == file(filename).read()
d8b73d9b679d separate testing fileapp to its own doctest file
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 True
30
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
23
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
24 With conditional_response on, and with last_modified and etag set, we
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
25 can do conditional requests::
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
26
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
27 >>> content_length = os.path.getsize(filename)
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
28 >>> content_length # don't ask me why the 'L'
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
29 6L
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
30 >>> req = Request.blank('/')
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
31 >>> res = req.get_response(app)
33
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
32 >>> print res
30
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
33 200 OK
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
34 Content-Type: text/plain; charset=UTF-8
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
35 Content-Length: 6
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
36 Last-Modified: ... GMT
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
37 ETag: ...-...
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
38 <BLANKLINE>
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
39 hello
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
40 <BLANKLINE>
31
f00fcf6d9f1d test not modified response
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
41 >>> req2 = Request.blank('/')
f00fcf6d9f1d test not modified response
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
42 >>> req2.if_none_match = res.etag
f00fcf6d9f1d test not modified response
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
43 >>> req2.get_response(app)
f00fcf6d9f1d test not modified response
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
44 <Response ... 304 Not Modified>
f00fcf6d9f1d test not modified response
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
45 >>> req3 = Request.blank('/')
f00fcf6d9f1d test not modified response
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
46 >>> req3.if_modified_since = res.last_modified
f00fcf6d9f1d test not modified response
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
47 >>> req3.get_response(app)
f00fcf6d9f1d test not modified response
Jeff Hammel <jhammel@mozilla.com>
parents: 30
diff changeset
48 <Response ... 304 Not Modified>
33
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
49
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
50 We can even do Range requests::
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
51
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
52 >>> req = Request.blank('/')
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
53 >>> res = req.get_response(app)
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
54 >>> req2 = Request.blank('/')
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
55 >>> # Re-fetch the first 3 bytes:
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
56 >>> req2.range = (0, 3)
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
57 >>> res2 = req2.get_response(app)
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
58 >>> res2
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
59 <Response ... 206 Partial Content>
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
60 >>> res2.body
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
61 'hel'
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
62 >>> # Now, conditional range support:
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
63 >>> req3 = Request.blank('/')
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
64 >>> req3.if_range = res.etag
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
65 >>> req3.range = (0, 3)
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
66 >>> req3.get_response(app)
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
67 <Response ... 206 Partial Content>
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
68 >>> req3.if_range = 'invalid-etag'
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
69 >>> req3.get_response(app)
86b519dd8467 finish test and implementation
Jeff Hammel <jhammel@mozilla.com>
parents: 31
diff changeset
70 <Response ... 200 OK>