Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install webunit2

How to install webunit2

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install webunit2
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.2.2 Available View build log
0.2.1 Available View build log
0.1 Available View build log
0.1.dev-20110417 Failed View build log
Windows (64-bit)
0.2.2 Available View build log
0.2.1 Available View build log
0.1 Available View build log
0.1.dev-20110417 Failed View build log
Mac OS X (10.5+)
0.2.2 Available View build log
0.2.1 Available View build log
0.1 Available View build log
0.1.dev-20110417 Failed View build log
Linux (32-bit)
0.2.2 Available View build log
0.2.1 Available View build log
0.1 Available View build log
0.1.dev-20110417 Failed View build log
Linux (64-bit)
0.2.2 Available View build log
0.2.1 Available View build log
0.1 Available View build log
0.1.dev-20110417 Failed View build log
 
License
GPL
Dependencies
Imports
Lastest release
version 0.2.2 on May 23rd, 2012

webunit2 is a spiritual successor to Richard Jones' webunit, but is by no means a fork. This library has been built from the ground up, complete with documentation and testing. It's also hosted on GitHub, making it a cinch to fork.

Documentation

Documentation is available on PyPi..

You can also build the documentation yourself. Make sure Sphinx is installed by running:

$ easy_install -U sphinx

Then, clone the repository, cd into it, and run:

$ python setup.py build_sphinx

Documentation is available in build/sphinx/html.

Getting Started

Getting started is really, really easy. All you need to do is implement webunit2.testcase.Testcase and start writing unit tests.

import webunit2

class TestMyApp(webunit2.TestCase):

    def __init__(self):
        # You aren't required to initialize the base class here, but it
        # makes dealing with subsequent requests easier--because they can
        # be relative paths!
        webunit2.TestCase.__init__(self, "http://myapp.com")

    def test_some_url(self):
        # Just do a normal get
        self.get('/somepath')

        # Lets post some data
        self.post('/somepath', post_params={"key": "value"})

        # No helper function for your HTTP method?  No problem!
        self.make_request("HEAD", "/somepath")

Of course, because this is a unit testing framework, you'll probably be making a lot of assertions--especially in content. That's easy too!

def test_for_content(self):
    # Assert the word `hippo` appears in the content.
    self.get_assertContent('/something', content="hippo")
    # Assert that the `X-Customheader` header was set.
    self.get_assertHeader('/something', 'X-Customheader')

If either of these fail (i.e., the return code is not 200 or the content does not contain hippo), an AssertionError is raised as normal. And of course, if you need to check for multiple values on the response, the same assert* functions are available directly on the response. For example, the above could be rewritten as:

def test_for_content_resp(self):
    resp = self.get('/something')
    # Assert the word `hippo` appears in the content.
    resp.assertContent("hippo")
    # Assert that the `X-Customheader` header was set.
    resp.assertHeader('X-Customheader')

This also allows you to chain many more assertions together--i.e., checking for headers, cookies, etc.. These were all designed to make testing easier, so if you have suggestions or complaints...

Contributing

The source code is hosted on Github, which makes it a cinch to fork and contribute. Please submit issues using the GitHub tracker! I love getting feedback, and I urge you to file tickets for features and/or bugs.

Subscribe to package updates

Last updated May 23rd, 2012

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.