annotate tests/test_fileapp.txt @ 30:52103702a732

figured out the magical code for doctest.ELLIPSIS
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 05 Mar 2012 13:40:15 -0800
parents d8b73d9b679d
children f00fcf6d9f1d
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)
52103702a732 figured out the magical code for doctest.ELLIPSIS
Jeff Hammel <jhammel@mozilla.com>
parents: 29
diff changeset
32 >>> print res # doctest:+ELLIPSIS
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>