Django Chutney
Tasty accompaniments to go with the Django web framework
My personal collection of miscellaneous useful bits of code for use in Django projects.
Installation
pip install django-chutney
Usage
The library is intended to be a pick and mix bucket from which you can choose to use whichever bits you want.
Test case helpers
These require BeautifulSoup to be installed:
pip install beautifulsoup4>=4
FormHelper
This provides functionality to allow you to test HTML forms in a way that's more accurate than the
standard approach with django.test.Client.
A common approach to testing form submissions to Django views is to submit a dict of data to the view,
but simply doing that doesn't check that the HTML form you're rendering actually allows those values
to be submitted. For example, your test case might submit a value for a field which isn't an option
in the rendered <select>. This approach also means that you may not be submitting values which would
be automatically submitted by a web browser, such as hidden fields.
django_chutney.test_utils.FormHelper provides a way for a test case to to submit a form while
checking that the values you're submitting are actually value that the browser would allow a user
to submit. It also automatically submits the values of any hidden inputs the form.
from django.test import TestCase
from django_chutney.test_utils import FormHelper
class MyFormTestCase(TestCase, FormHelper):
def test_form_page(self):
page_response = self.client.get(reverse("my_view"))
# Submit a form to the page, with automatic checking that the values you're submitting are
# possible values for a browser to submit based on the HTML of the form in the page.
# Also submits hidden values that are in the form, even if you don't specific them.
data = {"field1": "some-value"}
post_response = self.submit_form(response, "#my-form", data)
self.assertEqual(post_response.status_code, 302)
SoupHelper
This class provides additional helper methods for testing pages using BeautifulSoup.
assert_link_in_soup(url: str, soup: bs4.BeautifulSoup)
Tests that the given URL appears in a link (<a/> tag) in the given soup, while being order-insensitive
about the order of query params.
assert_text_in_soup(text, soup, tag: str | None = None, exact=False)
Tests that the given text appears in the soup, optionally inside the given type of tag.
If exact is True then the tag must contain only the given text.
find_element_containing_text(soup, text, tax=None, exact=False) -> bs4.BeautifulSoup | None
Similar to assert_text_in_soup, but returns the first found element which matches.
from django.test import TestCase
from django_chutney.test_utils import SoupHelper
class MyTestCase(TestCase, SoupHelper):
def test_page(self):
response = self.client.get(reverse("my_view"))
soup = self.soup(response)
# Test that a link to a specific URL exists, with order-insensitive query params
self.assert_link_in_soup("https://www.thing.com/?unordered=query¶ms=value", soup)
self.assert_text_in_soup("Hello", soup)
table_row = self.find_element_containing_text("John Smith")
# The table row should contain a link to the user's profile
self.assert_link_in_soup("/user/profile/{john_smith.pk}/", table_row)
Template tags & filters
get filter
Allows you to use a variable in the template as a key to extra an item from a dict to to extract an attribute value from an object.
In Django templates, doing {{obj.my_key}} will try to do obj["my_key"]. So you can't use a
variable to supply the key.
This filter allows you to do {{obj|get:my_var}}, which will do obj[my_var] instead.
{% load chutney_tags %}
<p>
{{ my_dict|get:my_var }}
</p>
Metadata
Release files for django-chutney 0.2.3
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 | |
|---|---|---|---|---|
| django_chutney-0.2.3.tar.gz | 8.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_chutney-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.5 kB
Release files / django_chutney-0.2.3.tar.gz
| Download URL | django_chutney-0.2.3.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c78fe0e75f622ad01a42aa89cb207cfcecf11884ef6073caf593f8368657f3aa
|
|
BLAKE2b-256 checksum How to use checksums |
9aeba60b56bf68a0422f81a7a0ef34ff4875c572e8ff8e91bb5c627a37ef9456
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 17, 2025.
Transparency logRelease files / django_chutney-0.2.3-py3-none-any.whl
| Download URL | django_chutney-0.2.3-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c01bd6662b95505b43da81712e040c1670f58f3ab257b158a86810cebc8da87
|
|
BLAKE2b-256 checksum How to use checksums |
68b1e88c0e92eb2b843a4d285e53f286d70a3c0641b2ccef7f7a62e2389aba4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 17, 2025.
Transparency logSecurity for django-chutney 0.2.3
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for django_chutney-0.2.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 17, 2025.
Transparency logA 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.