The test module defines a new test client, base testcase, testing mixins, and an alternate test runner.
hilbert.test.Client is a simple extension of the Django test client which allows for an extra argument in get and post called is_ajax. This will default to False but when passed as True it will make the request as an AJAX request.
hilbert.test.TestCase is an extension of the Django TestCase which uses the above test client and defines some helpful methods.
This method is used to generate random string data used in various tests.
A random string
This method is used to generate random email for the given domain.
|Parameters:||domain – The domain name for the email address|
|Returns:||A random email address as a string|
This generates a new django.contrib.auth.User. If no data is given then the user will be given a random username, email, and password.
|Parameters:||data – A dictionary of data for the user. Allowed keys: username, password, email|
|Returns:||A newly created User model|
The CoverageRunner is a new test runner based on snippets 705 and 2052. It uses Ned Batchelder’s coverage.py to determine the percent of code executed by the test suite. It can be enabled by setting TEST_RUNNER=’hilbert.test.CoverageRunner’ in your Django settings file. You must also define a set of submodules to be included in the report using the setting COVERAGE_MODULES.
COVERAGE_MODULES = ( 'decorators', 'http', 'forms', 'models', 'views', )
Using this setting the test runner will report the coverage of listed submodules of the tested apps (if they exist).
New in version 0.4.
If you usually want to pass the same set of test labels when you run tests, you can set DEFAULT_TEST_LABELS in your settings.
DEFAULT_TEST_LABELS = ['app1', 'app2.TestClass', 'app3.TestClass.test_method']
Then django-admin.py test will act like
django-admin.py test app1 app2.TestClass app3.TestClass.test_method
If you’ve done that, you can still pass ‘all’ on the command line to run tests as if you had not passed any test labels, e.g. run test all.
This is a testing mixin to help writing tests for your Django views. It will automatically reverse the data returned by get_url() and attach it to self.url. It also contains one test which does a GET request on the url.
New in version 0.3.
The ViewTestMixin changed in version 0.3 to expect a class attribute url_name.
class DashboardTestCase(TestCase, ViewTestMixin): url_name = 'dashboard'
If your url needs either args or kwargs you can override get_url_args or get_url_kwargs.
AuthViewMixin extends the ViewTestMixin for testing views which require authentication. It automatically creates a user and signs them in for any requests. It adds an additional test to ensure that authentication is required. This must be used in conjunction with hilbert.test.TestCase.