test_plus package¶
Submodules¶
test_plus.runner module¶
-
class
test_plus.runner.
NoLoggingRunner
(pattern=None, top_level=None, verbosity=1, interactive=True, failfast=False, keepdb=False, reverse=False, debug_mode=False, debug_sql=False, parallel=0, tags=None, exclude_tags=None, **kwargs)[source]¶ Bases:
django.test.runner.DiscoverRunner
-
run_tests
(test_labels, extra_tests=None, **kwargs)[source]¶ Run the unit tests for all the test labels in the provided list.
Test labels should be dotted Python paths to test modules, test classes, or test methods.
A list of ‘extra’ tests may also be provided; these tests will be added to the test suite.
Returns the number of tests that failed.
-
test_plus.test module¶
-
class
test_plus.test.
APITestCase
(*args, **kwargs)[source]¶ Bases:
test_plus.test.TestCase
-
class
test_plus.test.
BaseTestCase
(*args, **kwargs)[source]¶ Bases:
object
Django TestCase with helpful additional features
-
assertGoodView
(url_name, *args, **kwargs)[source]¶ Quick-n-dirty testing of a given url name. Ensures URL returns a 200 status and that generates less than 50 database queries.
-
assertResponseContains
(text, response=None, html=True, **kwargs)[source]¶ Convenience wrapper for assertContains
-
assertResponseHeaders
(headers, response=None)[source]¶ Check that the headers in the response are as expected.
Only headers defined in headers are compared, other keys present on the response will be ignored.
Parameters: - headers (
collections.Mapping
) – Mapping of header names to expected values - response (
django.http.response.HttpResponse
) – Response to check headers against
- headers (
-
assertResponseNotContains
(text, response=None, html=True, **kwargs)[source]¶ Convenience wrapper for assertNotContains
-
make_user
(username='testuser', password='password', perms=None)[source]¶ Build a user with <username> and password of ‘password’ for testing purposes.
-
print_form_errors
(response_or_form=None)[source]¶ A utility method for quickly debugging responses with form errors.
-
request
(method_name, url_name, *args, **kwargs)[source]¶ Request url by name using reverse() through method
If reverse raises NoReverseMatch attempt to use it as a URL.
-
reverse
(name, *args, **kwargs)[source]¶ Reverse a url, convenience to avoid having to import reverse in tests
-
user_factory
= None¶
-
-
class
test_plus.test.
CBVTestCase
(*args, **kwargs)[source]¶ Bases:
test_plus.test.TestCase
Directly calls class-based generic view methods, bypassing the Django test Client.
This process bypasses middleware invocation and URL resolvers.
Example usage:
from myapp.views import MyClass
class MyClassTest(CBVTestCase):
- def test_special_method(self):
request = RequestFactory().get(‘/’) instance = self.get_instance(MyClass, request=request)
# invoke a MyClass method result = instance.special_method()
# make assertions self.assertTrue(result)
-
assertGoodView
(url_name, *args, **kwargs)[source]¶ Quick-n-dirty testing of a given view. Ensures view returns a 200 status and that generates less than 50 database queries.
-
get
(cls, *args, **kwargs)[source]¶ Calls cls.get() method after instantiating view class. Renders view templates and sets context if appropriate.
-
get_instance
(cls, *args, **kwargs)[source]¶ Returns a decorated instance of a class-based generic view class.
Use initkwargs to set expected class attributes. For example, set the object attribute on MyDetailView class:
instance = self.get_instance(MyDetailView, initkwargs={‘object’: obj}, request)because SingleObjectMixin (part of generic.DetailView) expects self.object to be set before invoking get_context_data().
Pass a “request” kwarg in order for your tests to have particular request attributes.
-
class
test_plus.test.
TestCase
(*args, **kwargs)[source]¶ Bases:
django.test.testcases.TestCase
,test_plus.test.BaseTestCase
Django TestCase with helpful additional features
-
user_factory
= None¶
-
Module contents¶
-
class
test_plus.
APITestCase
(*args, **kwargs)[source]¶ Bases:
test_plus.test.TestCase
-
class
test_plus.
TestCase
(*args, **kwargs)[source]¶ Bases:
django.test.testcases.TestCase
,test_plus.test.BaseTestCase
Django TestCase with helpful additional features
-
user_factory
= None¶
-