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 django-viewtester

How to install django-viewtester

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install django-viewtester
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
10.4.3 Available View build log
Windows (64-bit)
10.4.3 Available View build log
Mac OS X (10.5+)
10.4.3 Available View build log
Linux (32-bit)
10.4.3 Available View build log
Linux (64-bit)
10.4.3 Available View build log
 
License
BSD
Dependencies
Lastest release
version 10.4.3 on Jan 5th, 2011

What is it?

A django-application to automate creating tests for views.

Requirements

  • django-1.1
  • jquery 1.4+ (optional though advisable).

It is assumed jquery is already loaded in your template(s). If not add this line in the (extra)head-section:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

Credits

Based on ideas and code from Eric Holscher's testmaker in test-utils.

How to get it?

You can download compressed archives from bitbucket or clone the repository using mercurial. I hope to make it available via PYPI sometime soon.

Usage

Add viewtester to your INSTALLED_APPS and include it in your urls.py then run:

$./manage.py run_viewtester [-f fixture.xml] appname

then open your browser and go to http://localhost:8000/.

Click around and see the results in the generated test-file. If all goes well you should be able to run the resulting tests without any further ado:

$./manage.py test appname

System Message: ERROR/3 (<string>, line 51)

Content block expected for the "note" directive; none found.

.. note::

System Message: WARNING/2 (<string>, line 52)

Explicit markup ends without a blank line; unexpected unindent.

The __init__.py that comes with viewtester imports all TestCase classes from all modules in the tests-directory. It is only created if the tests-dir doesn't exist when run_viewtester is started.

Overview

Once added to a project's settings and urls.py you can use the run_viewtester command to run the testserver with an app-name as an argument and optionally a (set of) fixture to populate the database. This follows the pattern of a django TestCase.

The command injects middleware that logs all requests to the specified app and resulting response status' to a test-module formated as django TestCases. Tests will be saved to appname/tests/YYYYMMDD-NN.py. You can override this on the commandline using the -l flag.

The middleware will also track any logging in or out you'll do and have the test-client log in or out accordingly in the tests.

An html-div, the 'panel', is injected into the response content that contains information about the current TestCase: Classname and loaded fixtures, current test-method-name and user. You can collapse the div by clicking on the title and it can be dragged to a non-intrusive place thanks to the magic of jquery-ui. It will remember where you dragged it too.

The panel contains a number of forms that allow you to:

  • Create a new Class, optionally with a set of fixtures that it will

System Message: WARNING/2 (<string>, line 83)

Bullet list ends without a blank line; unexpected unindent.

also be loaded upon submit. The fixtures can be picked from a pre-populated multiselect control which contains all the files in appname/fixtures.

  • Start a new test-method which will also reset the database to the

System Message: WARNING/2 (<string>, line 88)

Bullet list ends without a blank line; unexpected unindent.

state it will be when the resulting tests are run: It will be flushed and the class' fixtures are loaded.

  • Check the template context-variables by saving assertEqual

System Message: WARNING/2 (<string>, line 92)

Bullet list ends without a blank line; unexpected unindent.

statements into the tests by selecting variable-names from a multi-select control.

  • Save the current database-state for the specified app to a fixture

System Message: WARNING/2 (<string>, line 96)

Bullet list ends without a blank line; unexpected unindent.

to use in later tests. Fixtures will be saved to appname/fixtures/ using the name provided. The fixture name should follow the name.format pattern so it can infer the format from the extension. Only json and xml are supported. Fixtures are saved with --indent==2 for easy perusal.

Subscribe to package updates

Last updated Jan 5th, 2011

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.