Skip to main content

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

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 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 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 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 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.

Release files for django-viewtester 10.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-viewtester 10.4.3
File Size Uploaded
django-viewtester-10.4.3.tar.gz 13.5 kB Details

Release files / django-viewtester-10.4.3.tar.gz

Download URL django-viewtester-10.4.3.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
57efe3a1cfed049a515959b7d6e68fd7466cb7a48e806effe5d16a950d846c71
BLAKE2b-256 checksum
How to use checksums
44396c18c016f81c3cb64fcba4dd59b64520785eb96911ab6eaf4df2051ce1e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

10.4.3 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page