Skip to main content

A TestCaseMixin utility.

Project description


.. image::

django-testcase provides a TestCase mixin to provide new useful functions for Django tests.

Supports Django 1.10 and later, only with Python 3.4 and later.



$ pip install django-testcase

Basic usage

Simply subclass it in a ``TestCase``::

from django.test import TestCase
from django_testcase import TestCaseMixin

class LoginViewTestCase(TestCaseMixin, TestCase):
def test_login(self):

Available methods

``.create_user(username='test', email='', password='test', is_superuser=False, *args, **kwargs)``

Create a user with the given attributes. Any extra arguments passed will be passed to the creation call as is.


Allows testing Django's TestCase output system calls. Usage::

with capture_output() as sys:

In this situation, ``sys`` is a mocked object and can be tested with ``unittest.mock`` methods.

``.login(username='test', password='test', create_superuser=False)``

Logs the user in. If the user does not exist, it will be created, taking ``is_superuser`` into consideration.


Logs the user out.


Asserts the given user is authenticated.


Assets there is no user authenticated.

``.assertRedirectsToLogin(response, next_url=None)``

Asserts a given response redirects to the login page specified by ``settings.LOGIN_URL``, with a ``?next=`` URL if the parameter is given.

``.assertIssuedMessage(response, level, message)``

Checks if the message ``message`` with level ``level`` has been issued. Only an exact match is accepted.

``.jpost(url, data)``

Sends ``data`` as a POST payload to ``url``.

``.create(klass, *args, **kwargs)``

Creates an object of class ``klass`` with the passed arguments. Calls ``.full_clean()`` before saving.

Development tasks

Install for development and with dependencies::

$ python install -e .[dev]

Asserting code quality


$ python quality

Packaging for PyPI distribution


$ python package

The build will happen if the repository passes the quality tests and is clean: no untracked files are found. If not, you can see what's wrong with ``git clean -dfx --dry-run`` and remove or track and commit those files.

Builds will be available at ``dist``, in wheel and source.


Pull requests are welcome.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-testcase, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size django_testcase-0.1.1-py3-none-any.whl (4.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-testcase-0.1.1.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page