view tests/test_fileapp.txt @ 32:0edb831061f5

test not modified response
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 05 Mar 2012 14:06:00 -0800
parents f00fcf6d9f1d
children 86b519dd8467
line wrap: on
line source

Test FileApp
============

The obligatory imports::

    >>> import fileserver
    >>> import os
    >>> from paste.fixture import TestApp
    >>> from webob import Request

Make a single file server::

    >>> filename = os.path.join(here, 'example', 'helloworld.txt')
    >>> os.path.exists(filename)
    True
    >>> app = fileserver.FileApp(filename)
    >>> testapp = TestApp(app)
    >>> response = testapp.get('/')
    >>> response.status
    200
    >>> response.body == file(filename).read()
    True

With conditional_response on, and with last_modified and etag set, we
can do conditional requests::

    >>> content_length = os.path.getsize(filename)
    >>> content_length # don't ask me why the 'L'
    6L
    >>> req = Request.blank('/')
    >>> res = req.get_response(app)
    >>> print res 
    200 OK
    Content-Type: text/plain; charset=UTF-8
    Content-Length: 6
    Last-Modified: ... GMT
    ETag: ...-...
    <BLANKLINE>
    hello
    <BLANKLINE>
    >>> req2 = Request.blank('/')
    >>> req2.if_none_match = res.etag
    >>> req2.get_response(app)
    <Response ... 304 Not Modified>
    >>> req3 = Request.blank('/')
    >>> req3.if_modified_since = res.last_modified
    >>> req3.get_response(app)
    <Response ... 304 Not Modified>