view tests/doctest.txt @ 9:68db1111f23a

serve file contents, pt 2
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 29 Feb 2012 14:51:27 -0800
parents 782e15b86b86
children 1a11c096284b
line wrap: on
line source

Test FileServer
================

The obligatory imports::

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

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

Make a directory server::

    >>> directory = os.path.join(here, 'example')
    >>> os.path.exists(directory) and os.path.isdir(directory)
    True
    >>> app = fileserver.DirectoryServer(directory)
    >>> testapp = TestApp(app)

Ensure you can serve directory listings::

    >>> response = testapp.get('/')
    >>> response.status
    200
    >>> 'helloworld.txt' in response.body
    True

Ensure you can serve file contents::

    >>> response = testapp.get('/helloworld.txt')
    >>> response.status
    200
    >>> response.body == file(filename).read()
    True