point into Viceroy is
viceroy.api.build_test_case(), which will build
a test case class for you (and return it). It takes the following arguments:
class_name: The name of the class you want to build.
source_file: Full path to the source file.
scanner_class: Class that scans your
base_class: Base class for the test case, this will depend on your Python framework of choice.
- All other keyword arguments will be set as class attributes on the class
being built. A common keyword argument is
viceroy_urlwhich is the URL at which your test view is served.
Viceroy will set
True when running Viceroy
viceroy.contrib.django.urls in your urls. This will allow you to
True and otherwise will always return
a 404 response.
You may optionally install the
viceroy.contrib.django.context_processor.viceroy context processor, which
will set the template context variable
True if the
template is being rendered in a Viceroy test.
- QUnit itself.
viceroy.jswhich can be served from the urls you included above.
qunit-bridge.jswhich can also be served from the urls you included above.
- Your test file.
Assuming your test file is located at
/path/to/tests.js on your filesystem,
and the url to the view that loads the tests at
/test-url/ you would build
the test class as follows:
from viceroy.api import build_test_case from viceroy.contrib.django import ViceroyDjangoTestCase from viceroy.contrib.qunit import QUnitScanner MyTestCase = build_test_case( 'MyTestCase', '/path/to/tests.js', QUnitScanner, ViceroyDjangoTestCase, viceroy_url='/test-url/' )
- Jasmine itself.
viceroy.jsfrom the included urls.
jasmine-bridge.jsfrom the included urls.
- Your test file.
Build the test case as described in QUnit, but replace the
JasmineScanner, which you can import from
For your convenience, you may use
which is the path to the directory holding
VICEROY_TESTING in your
app.config will be set to
Testing in Flask works pretty much the same as Django, but substitute
ViceroyFlaskTestCase and make sure to
pass your Flask app as the
viceroy_flask_app keyword argument to
Besides the required
viceroy_flask_app extra keyword argument to
build_test_case there are the following optional configuration values:
viceroy_flask_port: Port to use, default
viceroy_flask_silent: Whether to hide the Werkzeug log, default