django-pigeon
Test utilities for Django projects
Installation
$ pip install django-pigeon
Usage
django-pigeon comes equipped with a RenderTestCase which provides an assortment of methods on top of Django's TestCase that assist with end-to-end testing of views in Django. Writing a test that verifies a view renders correctly is as simple as:
from pigeon.test import RenderTestCase
class FooTestCase(RenderTestCase):
def testFooView(self):
self.assertResponseRenders('/foo/')
You can also inspect the rendered response:
def testFooView(self):
response = self.assertResponseRenders('/foo/')
self.assertIn('FOO', response.content)
By default, assertResponseRenders verifies that the status code of the response is 200, but you can change this by specifying the status_code keyword argument:
def testBarView404(self):
self.assertResponseRenders('/bar/', status_code=404)
You can also make POST and PUT requests using assertResponseRenders by providing the method and data keywords arguments:
def testCreateFooView(self):
payload = {'text': 'Hello World!'}
self.assertResponseRenders('/foo/create/', status_code=201, method='POST', data=payload)
If you are using HTML generated from Django forms, you can set has_form_error=True as a shortcut to check for errorlist in the resulting HTML:
def testCreateFooViewWithoutText(self):
response = self.assertResponseRenders('/foo/create/', method='POST', has_form_error=True)
self.assertIn('This field is required.', response.content)
Use assertAPIResponseRenders for JSON responses. json.loads is automatically called on the response, so the object returned is ready for inspection:
def testFooAPIView(self):
payload = {'text': 'Hello!'}
response = self.assertAPIResponseRenders('/foo/', method='POST', data=payload)
self.assertEquals(response['text'], 'Hello!')
You can use assertResponseRedirects to test redirects:
def testFooRedirects(self):
# /foo/ redirects to /bar/
self.assertResponseRedirects('/foo/', '/bar/')
If you have a list of views that you want to verify are rendering as 200 without adding any special assertion logic, you can simply override the get200s and getAPI200s methods, which should return a list of URLs. django-pigeon will construct test methods that check that rendering all of these URLs results in a 200:
class FooTestCase(RenderTestCase):
def get200s(self):
return [
'/foo/',
'/bar/',
'/foobar/',
]
def getAPI200s(self):
return [
'/api/foo/',
]
Most of the features in RenderTestCase are actually implemented in the mixin class RenderTestCaseMixin. You can combine RenderTestCaseMixin with other TestCase classes to get additional functionality:
from django.test import TransactionTestCase
from pigeon.test import RenderTestCaseMixin
class FooTransactionTestCase(RenderTestCaseMixin, TransactionTestCase):
def testFooView(self):
...
django-pigeon supports Python 3.5+ and Django 2.2+.
Metadata
Release files for django-pigeon 0.4.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 |
|---|---|---|---|---|
| django-pigeon-0.4.0.tar.gz | 4.6 kB | Without provenance | Details for django-pigeon-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_pigeon-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for django_pigeon-0.4.0-py3-none-any.whl |
Total release size: 9.4 kB
Release files / django-pigeon-0.4.0.tar.gz
| Download URL | django-pigeon-0.4.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
528407a3d8e6fa1e57f79155a809f90ed882d31bd394e9244a4e0c832ebd34e4
|
|
BLAKE2b-256 checksum How to use checksums |
5ff238a87b147b8f3db5122b032f6111251e857486f8ac97a207a95bf492aeb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.7 Linux/4.15.0-1077-gcp
|
Release files / django_pigeon-0.4.0-py3-none-any.whl
| Download URL | django_pigeon-0.4.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aaa94e55ff10eb4dfc157ca74bc39a64fe94d7ed0e0fb316d2778e4ff0a0e091
|
|
BLAKE2b-256 checksum How to use checksums |
08777d6494f92cc81ff6fd2ff2b1597a70ba4b0d0fcd18a50e0069f12d3716fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.7 Linux/4.15.0-1077-gcp
|
Security for django-pigeon 0.4.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.