Mercurial > hg > FileServer
annotate tests/test_fileapp.txt @ 31:f00fcf6d9f1d
test not modified response
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 05 Mar 2012 13:49:07 -0800 |
parents | 52103702a732 |
children | 86b519dd8467 |
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) |
31
f00fcf6d9f1d
test not modified response
Jeff Hammel <jhammel@mozilla.com>
parents:
30
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> |