view tests/test_ttw.txt @ 64:bb8d993376aa

* convenience methods for multipart form * include this in test globals
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 01 Mar 2012 18:15:34 -0800
parents 7c154953acc4
children 83327bc715be
line wrap: on
line source

Test Through The Web
====================

Test ``simpypi`` through the web with a test server.

The obligatory imports::

    >>> import urllib2
    >>> from simpypi.factory import factory

Create a WSGI app::

    >>> app = factory(directory=directory)

Now wrap it in a server::

    >>> port = 64321
    >>> server = testserver(app, 'localhost', port)
    >>> server.start()
    >>> url = 'http://localhost:%d/' % port

Get the home page::

    >>> resource = urllib2.urlopen(url)
    >>> contents = resource.read()
    >>> 'Python Package Index' in contents
    True

Get the index page::

    >>> resource = urllib2.urlopen(url + 'index')
    >>> contents = resource.read()
    >>> 'Simple Index' in contents
    True

Shut down the server::

    >>> server.stop()