incuna-test-utils
Incuna Test Utils is a collection of TestCases and other helpers for testing Django apps.
TestCases
These are found in incuna_test_utils.testcases.
urls.URLTestCase
URLTestCase adds assert_url_matches_view to check a url has been configured
to use the correct view.
request.BaseRequestTestCase
BaseRequestTestCase provides various helper methods for working with django
views:
get_viewreturns a view callable based on aviewattribute set on theTestCaseclass.viewcan be either a function-based or a class-based view.view_instancereturns an instance of a class-basedviewattribute set on theTestCaseclass.view_instanceaccepts arequestand*argsand**kwargs. These are set on theviewinstance.add_session_to_requestgives arequestasession.create_userreturns auserusing eitherAnonymousUseror auser_factoryattribute set on theTestCase. Theuser_factoryshould have acreatemethod that returns auser.factory_boyis recommended.create_requestwraps Django'sRequestFactoryto provide useful defaults. It returns arequestwithuserand_messagesattributes. It can also setDATAandsessionon therequest.
integration.BaseAdminIntegrationTestCase
BaseAdminIntegrationTestCase provides a TestCase to test the django admin actions
such as add, change, changelist and delete.
BaseAdminIntegrationTestCase should be subclassed and should define two attributes:
- a
user_factoryto create an authenticated client; - a
modelto test.
Example:
from incuna_test_utils.testcases.integration import BaseAdminIntegrationTestCase
class TestUserAdmin(BaseAdminIntegrationTestCase):
user_factory = factories.UserFactory
model = ModelToTest
def test_admin_add_page(self):
response = self.get_admin_add_page()
self.assertEqual(response.status_code, 200)
...
integration.BaseIntegrationTestCase
BaseIntegrationTestCase extends BaseRequestTestCase and adds more helper
methods useful for integration tests:
access_viewcreates arequest, calls theTestCase'sviewand returns aresponse.render_to_strrenders aresponseusing arequest,response.template_nameandresponse.context_data. If arequestis not provided,render_to_strusesresponse.request.access_view_and_render_responsewrapsaccess_viewandrender_to_str. It also checks theresponse.status_codeis as expected. The defaultexpected_statusis200(HTTP_OK).assert_presencechecks that an item does or doesn't appear in a container.assert_countchecks that an item appears in a container an expected number of times.assert_presence_multipleandassert_count_multiplerun one or more assertions in a single method call.render_view_and_assert_contentandrender_view_and_assert_content_countscombine a call toaccess_view_and_render_responsewith a multiple-assert call on the result.
api_request.BaseAPIRequestTestCase
BaseAPIRequestTestCase extends BaseRequestTestCase for use with
django-rest-framework.
create_requestis overriden to use rest framework'sAPIRequestFactory. It also setsrequest.formatto'json'. If called withauth=True(the default),create_requestalso callsforce_authenticate.
Factories
These are found in incuna_test_utils.factories. They require
factory_boy.
user.BaseUserFactory
This defines a simple factory with an email attribute. This can be used with
a custom User model that has these fields:
class UserFactory(BaseUserFactory):
class Meta:
model = User
user.BaseAdminUserFactory
BaseAdminUserFactory defines a user with is_active, is_staff and
is_superuser to True. This factory also defines a post hook which
sets a default password accessible with raw_password.
feincms_page.PageFactory
This factory can be used to create instances of
Feincms's
Page model.
compat
compat provides a few miscelleaneous helpers useful for testing cross-version
code:
DJANGO_LT_19isTrueifdjango.VERSIONis less than1.9.Python2AssertMixinaliases python 2.7 assert methods to match the python 3 api.TestCase.assertItemsEqualis aliased asassertCountEqualTestCase.assertRegexpMatchesis aliased asassertRegex
Metadata
Release files for incuna-test-utils 8.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| incuna-test-utils-8.0.0.tar.gz | 19.1 kB | Without provenance | Details for incuna-test-utils-8.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| incuna_test_utils-8.0.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for incuna_test_utils-8.0.0-py2.py3-none-any.whl |
Total release size: 45.6 kB
Release files / incuna-test-utils-8.0.0.tar.gz
| Download URL | incuna-test-utils-8.0.0.tar.gz |
|---|---|
| Size | 19.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc8194d275bc39b94a62c737d58a8df506399778c806a0f465b9db725286927d
|
|
BLAKE2b-256 checksum How to use checksums |
01e8619c6f28d32782f153b1f1325a8d4052c27b208ebc740331188fa5797c47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6
|
Release files / incuna_test_utils-8.0.0-py2.py3-none-any.whl
| Download URL | incuna_test_utils-8.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 26.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
34b3f3a1f450bb96c646ecf029f4ea880ea5db25217659ec4f18f060c38dd5ae
|
|
BLAKE2b-256 checksum How to use checksums |
c2b8a8b660aceeca49bcecf0d77a9f47b339ee206043e2c06652b13aec77b9cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6
|
Security for incuna-test-utils 8.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.